Skip to content

Commit

Permalink
safe walk response when requesting accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesmac committed Nov 16, 2023
1 parent a16619e commit 1d4b895
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/crypto/src/contexts/Ethers/MetaMask.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const StorybookEntry = {
} as Meta<typeof MetaMaskEthersLoader>

const ConnectMetaMaskProvider = () => {
const { connect, chainId, error, isConnected, localAddress, provider, providerName, signer, walletProvider } = useEthersContext()
const { connect, connectRefused, chainId, error, isConnected, localAddress, provider, providerName, signer, walletProvider } = useEthersContext()
return (
<FlexCol alignItems="start" gap={2}>
<Button variant="contained" onClick={async () => await connect?.()}>
Expand All @@ -34,6 +34,7 @@ const ConnectMetaMaskProvider = () => {
<ListItem>Provider: {JSON.stringify(provider?._isProvider)}</ListItem>
<ListItem>Wallet Provider: {JSON.stringify(walletProvider?._isProvider)}</ListItem>
<ListItem>Signer: {JSON.stringify(signer?._isSigner)}</ListItem>
<ListItem>Connection Refused: {JSON.stringify(connectRefused)}</ListItem>
<ListItem>Error: {error?.message}</ListItem>
</List>
</FlexCol>
Expand Down
4 changes: 2 additions & 2 deletions packages/crypto/src/contexts/Ethers/MetaMask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface Props {
enabled?: boolean
}

export const MetaMaskEthersLoader: React.FC<PropsWithChildren<Props>> = ({ children, enabled }) => {
export const MetaMaskEthersLoader: React.FC<PropsWithChildren<Props>> = ({ children, enabled = true }) => {
const [error, setError] = useState<Error>()
const [resetCount, setResetCount] = useState(0)

Expand Down Expand Up @@ -74,7 +74,7 @@ export const MetaMaskEthersLoader: React.FC<PropsWithChildren<Props>> = ({ child
const connect = useCallback(async () => {
const accounts = await walletProvider?.send('eth_requestAccounts', [])
// We could have multiple accounts. Check for one.
if (accounts.length !== 0) {
if (accounts && accounts?.length !== 0) {
setLocalAddress(accounts[0])
console.log('Connected: ', accounts[0])
} else {
Expand Down

0 comments on commit 1d4b895

Please sign in to comment.