Skip to content

Commit

Permalink
Update Deployments with Chain States
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed May 1, 2024
1 parent db9f5f2 commit c9a5e34
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 45 deletions.
65 changes: 23 additions & 42 deletions web/components/organisms/deploy/DeploySOResolver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FC, useEffect, useMemo, useState } from "react";
import { useAccount, useChainId, useSimulateContract, useSwitchChain, useWriteContract } from "wagmi";
import { Address, formatEther } from "viem";
import { useDeployedResolvers } from "../../../stores/deployed_resolvers";
import { SORDeployments } from "../../../util/deployments";
import { SORDeployments, isSOREnabled } from "../../../util/deployments";

// https url that must include '{sender}'
// const gatewayRegex = new RegExp("^https://.*{sender}.*$");
Expand Down Expand Up @@ -38,7 +38,10 @@ export const DeployResolverCard: FC = () => {
const isGatewayUrlValid = gatewayRegex.test(gatewayUrl.trim());
const isSignersValid = signersRegex.test(signers.trim());

const isReady = isGatewayUrlValid && isSignersValid;
const enabledOnChain = isSOREnabled(chainId);
const isReadyForChain = enabledOnChain === 'available';

const isReady = isGatewayUrlValid && isSignersValid && isReadyForChain;

const factoryAddress = SORDeployments[chainId]?.[0]?.factory;

Expand All @@ -54,45 +57,7 @@ export const DeployResolverCard: FC = () => {

const { chains, switchChain } = useSwitchChain();

const {writeContract} = useWriteContract();

// const { write, data } = useContractWrite(config);
// const receipt = useWaitForTransaction(data);

// const gas = useMemo(() => {
// if (!EstimateData) return null;
// if (!FeeData) return null;
// if (!FeeData.gasPrice) return null;

// const num = FeeData.gasPrice.mul(EstimateData.request.gasLimit);
// const goerliOffset = chainId == 5 ? 1000n : 1n;

// return {
// // Is it me or is goerli fee data off by /1000
// gasTotal: formatEther(num.toBigInt() / goerliOffset, 'gwei').substring(0, 8),
// }
// }, [FeeData, EstimateData]);

// console.log({ receipt: receipt?.data });

// useEffect(() => {
// if (!data) return;

// logTransaction(data.hash, chainId.toString());
// }, [data]);

// useEffect(() => {
// if (!receipt?.data) return;

// const x = receipt.data;

// const first = x.logs[0];
// const address = first.address;

// console.log('Contracted Deployed at: ' + address);

// logTransactionSuccess(receipt.data.transactionHash, chainId.toString(), address);
// }, [receipt?.data]);
const { writeContract } = useWriteContract();

return (
<Card className="leading-6 gap-2">
Expand All @@ -111,6 +76,18 @@ export const DeployResolverCard: FC = () => {
options={chains.map((chain) => ({
value: chain.id.toString(),
label: chain.name,
node: <div className="flex justify-between">
<div>{chain.name}</div>
<div>
{(() => {
switch (isSOREnabled(chain.id)) {
case 'available': return <span className="text-green-500">Available</span>;
case 'deprecated': return <span className="text-yellow-500">Deprecated</span>;
case 'unavailable': return <span className="text-red-500">Unavailable</span>;
}
})()}
</div>
</div>
}))}
onChange={(event) => {
switchChain({
Expand Down Expand Up @@ -203,9 +180,13 @@ export const DeployResolverCard: FC = () => {
chainId,
functionName: 'createOffchainResolver',
args: [gatewayUrl, signersToArray(signers)],
}, {
onSuccess(data, variables, context) {
logTransaction(data, chainId.toString());;
}
})
}}>
{ isLoading ? 'Estimating Fees...' : isSuccess ? 'Deploy ' + EstimateData?.request.gas + ' gas' : 'Deploy'}
{isLoading ? 'Estimating Fees...' : isSuccess ? 'Deploy ' + EstimateData?.request.gas + ' gas' : 'Deploy'}
</Button>
);
})()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const DeployedResolvers = () => {
</div>
<div className="w-full">
{
transactionForChain.map((transaction) => <TransactionHistoryEntry key={`mod-tx-${transaction.hash}`} transaction={transaction} />)
transactionForChain.map((transaction) => <TransactionHistoryEntry key={`mod-tx-${transaction.hash}`} transaction={transaction} />).reverse()
}
</div>
</Card>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FC, useEffect } from "react";
import { FiExternalLink, FiLoader } from "react-icons/fi";
import { TransactionStatePending, useDeployedResolvers } from "../../../stores/deployed_resolvers";
import { explorer_urls } from "../../../util/deployments";
import { chainIdToName, explorer_urls } from "../../../util/deployments";
import { useWaitForTransactionReceipt } from "wagmi";

export const PendingResolver: FC<{ transaction: TransactionStatePending }> = ({ transaction }) => {
Expand Down Expand Up @@ -40,7 +40,7 @@ export const PendingResolver: FC<{ transaction: TransactionStatePending }> = ({
</span>
<span>on</span>
<span>
{transaction.chain}
{chainIdToName(Number.parseInt(transaction.chain))}
</span>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions web/util/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ type SORDeployment = {
version: SORVersion;
};

export const isSOREnabled = (chainId: number) => {
if (chainId == 5) return 'deprecated';
if (SORDeployments.hasOwnProperty(chainId) && SORDeployments[chainId].length > 0) return 'available';
return 'unavailable';
};

export const SORDeployments: Record<number, SORDeployment[]> = {
[mainnet.id]: [
{
Expand Down

0 comments on commit c9a5e34

Please sign in to comment.