Skip to content

Commit

Permalink
chore: refactor syncAccount params and resetAccount logics
Browse files Browse the repository at this point in the history
  • Loading branch information
enesozturk committed Aug 12, 2024
1 parent 3c52aee commit fb89acd
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions packages/wagmi/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,7 @@ export class Web3Modal extends Web3ModalScaffold {
isConnected: true,
addresses: response.accounts,
connector,
chainId: response.chainId,
status: 'connected',
resetAccount: false
chainId: response.chainId
})
)
}
Expand Down Expand Up @@ -461,9 +459,7 @@ export class Web3Modal extends Web3ModalScaffold {
isDisconnected,
chainId,
connector,
addresses,
status,
resetAccount = true
addresses
}: Partial<
Pick<
GetAccountReturnType,
Expand All @@ -475,19 +471,14 @@ export class Web3Modal extends Web3ModalScaffold {
| 'addresses'
| 'status'
>
> & { resetAccount?: boolean }) {
>) {
const caipAddress: CaipAddress = `${ConstantsUtil.EIP155}:${chainId}:${address}`

if (this.getCaipAddress() === caipAddress) {
return
}

const connected = isConnected && status === 'connected'

if (connected && address && chainId) {
if (resetAccount) {
this.resetAccount()
}
if (isConnected && address && chainId) {
this.syncNetwork(address, chainId, isConnected)
this.setIsConnected(isConnected)
this.setCaipAddress(caipAddress)
Expand All @@ -511,9 +502,7 @@ export class Web3Modal extends Web3ModalScaffold {

this.hasSyncedConnectedAccount = true
} else if (isDisconnected && this.hasSyncedConnectedAccount) {
if (resetAccount) {
this.resetAccount()
}
this.resetAccount()
this.resetWcConnection()
this.resetNetwork()
this.setAllAccounts([], this.chain)
Expand Down Expand Up @@ -818,8 +807,7 @@ export class Web3Modal extends Web3ModalScaffold {
address: address as `0x${string}`,
isConnected: true,
chainId: NetworkUtil.caipNetworkIdToNumber(this.getCaipNetwork()?.id),
connector,
status: 'connected'
connector
})
})
}
Expand Down

0 comments on commit fb89acd

Please sign in to comment.