-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
378 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
web/components/organisms/deployed_resolvers/DeployedResolvers.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { FC } from "react"; | ||
import { TransactionState, TransactionStateDeployed, TransactionStatePending, useDeployedResolvers } from "../../../stores/deployed_resolvers"; | ||
import { useChainId, useContractRead, useTransaction } from "wagmi"; | ||
import { Card, Input } from "@ensdomains/thorin"; | ||
import { formatEther } from "viem"; | ||
import { FiExternalLink, FiFile } from 'react-icons/fi'; | ||
|
||
export const DeployedResolvers = () => { | ||
const transactions = useDeployedResolvers(e => e.transactions); | ||
const chain = useChainId(); | ||
|
||
const transactionForChain = transactions.filter(transaction => transaction.chain == chain.toString()); | ||
|
||
return ( | ||
<div className="flex flex-col gap-2"> | ||
<Card className="!gap-0 !p-4"> | ||
<h2 className="font-bold">Deployed Resolvers</h2> | ||
<span>These are the resolvers you have deployed</span> | ||
</Card> | ||
<div className="flex flex-col gap-2"> | ||
{ | ||
transactionForChain.map((transaction) => transaction.status == "deployed" ? | ||
<DeployedResolver key={transaction.hash} transaction={transaction} /> : <PendingTransaction key={transaction.hash} transaction={transaction} />).reverse() | ||
} | ||
</div> | ||
</div> | ||
) | ||
}; | ||
|
||
export const PendingTransaction: FC<{ transaction: TransactionState }> = ({ transaction: { hash, chain } }) => { | ||
|
||
return ( | ||
<div className="bg-ens-light-background-primary bg-ens-light-border rounded-lg"> | ||
<div>Pending</div> | ||
<div>{hash}</div> | ||
<div>{chain}</div> | ||
</div> | ||
); | ||
}; | ||
|
||
const explorer_urls: Record<number, { | ||
transaction: string, | ||
address: string, | ||
}> = { | ||
1: { | ||
transaction: 'https://etherscan.io/tx/:hash', | ||
address: 'https://etherscan.io/address/:address' | ||
}, | ||
5: { | ||
transaction: 'https://goerli.etherscan.io/tx/:hash', | ||
address: 'https://goerli.etherscan.io/address/:address' | ||
}, | ||
}; | ||
|
||
export const DeployedResolver: FC<{ transaction: TransactionStateDeployed }> = ({ transaction }) => { | ||
const { data: gateway_data } = useContractRead({ | ||
address: transaction.contract_address as any, | ||
abi: [{ name: 'url', type: 'function', stateMutability: 'view', inputs: [], outputs: [{ name: 'url', type: 'string' }] }], | ||
functionName: 'url', | ||
enabled: true, | ||
}); | ||
const { data: transactionData } = useTransaction({ | ||
hash: transaction.hash as `0x${string}`, | ||
chainId: Number.parseInt(transaction.chain), | ||
}); | ||
|
||
const explorer_url = explorer_urls[Number.parseInt(transaction.chain)]; | ||
const gateway_url = gateway_data as string; | ||
|
||
return ( | ||
<Card className="!p-4"> | ||
<div className="flex gap-1 items-center"> | ||
<FiFile /> | ||
<a href={explorer_url.address.replace(":address", transaction.contract_address)} target="_blank" className="flex items-center justify-center gap-1 text-sm"> | ||
<span> | ||
{transaction.contract_address} | ||
</span> | ||
<FiExternalLink /> | ||
</a> | ||
</div> | ||
<div className=""> | ||
<div> | ||
Deployed at | ||
<div className="flex gap-2 items-center justify-center"> | ||
<div className="truncate text-sm font-bold"> | ||
{transaction.hash} | ||
</div> | ||
<a href={explorer_url.transaction.replace(":hash", transaction.hash)} target="_blank" className="flex items-center justify-center gap-1 text-sm"> | ||
TxHsh <FiExternalLink /> | ||
</a> | ||
</div> | ||
</div> | ||
<div className="flex justify-between"> | ||
<div> | ||
Total Gas Fees | ||
</div> | ||
<div className="flex items-center gap-1 text-sm"> | ||
<span> | ||
🔥 | ||
</span> | ||
<span className="items-center text-ens-light-red-bright"> | ||
{ | ||
formatEther( | ||
transactionData?.gasPrice?.mul(transactionData?.gasLimit).toBigInt() ?? BigInt(0)) | ||
} | ||
</span> | ||
</div> | ||
</div> | ||
<div className="pt-2"> | ||
<Input label="Gateway Url" defaultValue={gateway_url} /> | ||
</div> | ||
</div> | ||
</Card> | ||
|
||
) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { type } from 'os'; | ||
import { create } from 'zustand'; | ||
import { createJSONStorage, persist } from 'zustand/middleware'; | ||
|
||
export type TransactionStatePending = { status: 'pending', hash: string, chain: string }; | ||
export type TransactionStateDeployed = { status: 'deployed', hash: string, chain: string, contract_address: string }; | ||
|
||
export type TransactionState = TransactionStatePending | TransactionStateDeployed; | ||
|
||
interface DeployedResolverState { | ||
transactions: TransactionState[]; | ||
logTransaction: (transaction_hash: string, chain_id: string) => void; | ||
logTransactionSuccess: (transaction_hash: string, chain_id: string, contract_address: string) => void; | ||
} | ||
|
||
export const useDeployedResolvers = create( | ||
persist<DeployedResolverState>( | ||
(set) => ({ | ||
transactions: [], | ||
logTransaction(transaction_hash, chain_id) { | ||
set((state) => ({ transactions: [...state.transactions, { status: 'pending', hash: transaction_hash, chain: chain_id }] })) | ||
}, | ||
logTransactionSuccess(transaction_hash, chain_id, contract_address) { | ||
set((state): Partial<DeployedResolverState> => { | ||
const transactions = state.transactions.map((transaction) => { | ||
if (transaction.hash === transaction_hash) { | ||
return { ...transaction, status: 'deployed', contract_address } as TransactionStateDeployed; | ||
} else { | ||
return transaction; | ||
} | ||
}); | ||
|
||
return { transactions }; | ||
}) | ||
}, | ||
}), { name: '@ccip-tools/resolvers', storage: createJSONStorage(() => localStorage) })); |
Oops, something went wrong.