Skip to content

Commit

Permalink
fix: chain Id issue. remove unused logs
Browse files Browse the repository at this point in the history
  • Loading branch information
tomiir committed Feb 1, 2024
1 parent b48343c commit 8bc06be
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -58,9 +58,7 @@ export default function SmartAccountCard({
console.error(error)
}
}

const getFaucetUrl = () => `https://${name?.toLowerCase()?.replace('ethereum', '')?.trim()}faucet.com`


return (
<ChainCard rgb={rgb} flexDirection="row" alignItems="center" flexWrap="wrap">
<Avatar src={logo} />
Expand Down Expand Up @@ -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
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion advanced/wallets/react-wallet-v2/src/lib/SmartAccountLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ export const PIMLICO_NETWORK_NAMES: Record<Chain['name'], string> = {
Goerli: 'goerli'
}

export const FAUCET_URLS: Record<Chain['name'], string> = {
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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8bc06be

Please sign in to comment.