From 8bc06be0e6f59391990c367a6a43c3439575d815 Mon Sep 17 00:00:00 2001 From: tomiir Date: Wed, 31 Jan 2024 21:17:09 -0600 Subject: [PATCH] fix: chain Id issue. remove unused logs --- .../src/components/SmartAccountCard.tsx | 10 ++++------ .../react-wallet-v2/src/hooks/useSmartAccount.ts | 1 - .../wallets/react-wallet-v2/src/lib/SmartAccountLib.ts | 3 ++- .../react-wallet-v2/src/utils/SmartAccountUtils.ts | 8 ++++++++ .../react-wallet-v2/src/views/SessionProposalModal.tsx | 2 +- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/advanced/wallets/react-wallet-v2/src/components/SmartAccountCard.tsx b/advanced/wallets/react-wallet-v2/src/components/SmartAccountCard.tsx index f361a5cf8..8ac846845 100644 --- a/advanced/wallets/react-wallet-v2/src/components/SmartAccountCard.tsx +++ b/advanced/wallets/react-wallet-v2/src/components/SmartAccountCard.tsx @@ -8,7 +8,7 @@ import Image from 'next/image' import { useState } from 'react' import { useSnapshot } from 'valtio' import useSmartAccount from '@/hooks/useSmartAccount' -import { Chain, allowedChains } from '@/utils/SmartAccountUtils' +import { Chain, FAUCET_URLS, allowedChains } from '@/utils/SmartAccountUtils' interface Props { name: string @@ -29,7 +29,7 @@ export default function SmartAccountCard({ }: Props) { const [copied, setCopied] = useState(false) const { activeChainId } = useSnapshot(SettingsStore.state) - const chain = allowedChains.find((c) => c.id.toString() === chainId.split(':')[0]) as Chain + const chain = allowedChains.find((c) => c.id.toString() === chainId.split(':')[1]) as Chain const { deploy, isDeployed, @@ -58,9 +58,7 @@ export default function SmartAccountCard({ console.error(error) } } - - const getFaucetUrl = () => `https://${name?.toLowerCase()?.replace('ethereum', '')?.trim()}faucet.com` - + return ( @@ -126,7 +124,7 @@ export default function SmartAccountCard({ disabled={!isActiveChain || loading} size="sm" css={{ marginTop: 20, width: '100%' }} - onClick={() => window.open(getFaucetUrl(), '_blank')} + onClick={() => window.open(FAUCET_URLS[chain?.name], '_blank')} > {name} Faucet diff --git a/advanced/wallets/react-wallet-v2/src/hooks/useSmartAccount.ts b/advanced/wallets/react-wallet-v2/src/hooks/useSmartAccount.ts index 2f383d153..1d821ce37 100644 --- a/advanced/wallets/react-wallet-v2/src/hooks/useSmartAccount.ts +++ b/advanced/wallets/react-wallet-v2/src/hooks/useSmartAccount.ts @@ -40,7 +40,6 @@ export default function useSmartAccount(signerPrivateKey: Hex, chain: Chain) { }, [client, execute]) useEffect(() => { - console.log('chain', chain) if (!signerPrivateKey || !chain) return const smartAccountClient = new SmartAccountLib({ chain, diff --git a/advanced/wallets/react-wallet-v2/src/lib/SmartAccountLib.ts b/advanced/wallets/react-wallet-v2/src/lib/SmartAccountLib.ts index 5f0e65f89..960f3a96d 100644 --- a/advanced/wallets/react-wallet-v2/src/lib/SmartAccountLib.ts +++ b/advanced/wallets/react-wallet-v2/src/lib/SmartAccountLib.ts @@ -38,6 +38,7 @@ export class SmartAccountLib { if (!pimlicoApiKey) { throw new Error('A Pimlico API Key is required') } + this.chain = chain this.sponsored = sponsored this.#signerPrivateKey = privateKey @@ -256,7 +257,7 @@ export class SmartAccountLib { public checkIfSmartAccountDeployed = async () => { const smartAccountClient = await this.getSmartAccountClient(); - console.log('checking if deployed', smartAccountClient.account.address, this.chain.name) + console.log('Checking if deployed', smartAccountClient.account.address, this.chain.name) const bytecode = await this.publicClient.getBytecode({ address: smartAccountClient.account.address }) this.isDeployed = Boolean(bytecode) diff --git a/advanced/wallets/react-wallet-v2/src/utils/SmartAccountUtils.ts b/advanced/wallets/react-wallet-v2/src/utils/SmartAccountUtils.ts index 9378e4ca8..4ea710e42 100644 --- a/advanced/wallets/react-wallet-v2/src/utils/SmartAccountUtils.ts +++ b/advanced/wallets/react-wallet-v2/src/utils/SmartAccountUtils.ts @@ -46,6 +46,14 @@ export const PIMLICO_NETWORK_NAMES: Record = { Goerli: 'goerli' } +export const FAUCET_URLS: Record = { + Sepolia: 'https://sepoliafaucet.com', + 'Polygon Mumbai': 'https://faucet.polygon.technology', + Goerli: 'https://goerlifaucet.com' +} + +export const USDC_FAUCET_URL = 'https://faucet.circle.com/' + export const VITALIK_ADDRESS = '0xd8da6bf26964af9d7eed9e03e53415d37aa96045' as Hex export const publicRPCUrl = ({ chain }: UrlConfig) => RPC_URLS[chain.name] diff --git a/advanced/wallets/react-wallet-v2/src/views/SessionProposalModal.tsx b/advanced/wallets/react-wallet-v2/src/views/SessionProposalModal.tsx index 99d017ef7..e29b6eaaf 100644 --- a/advanced/wallets/react-wallet-v2/src/views/SessionProposalModal.tsx +++ b/advanced/wallets/react-wallet-v2/src/views/SessionProposalModal.tsx @@ -236,7 +236,7 @@ export default function SessionProposalModal() { }) // TODO: improve for multi network - console.log('checking if SA is deployed', eip155Wallets[eip155Addresses[0]]) + console.log('Checking if SA is deployed', eip155Wallets[eip155Addresses[0]]) const chainId = namespaces['eip155'].chains?.[0] const smartAccountClient = new SmartAccountLib({ privateKey: eip155Wallets[eip155Addresses[0]].getPrivateKey() as Hex,