Skip to content

Commit

Permalink
fix: remove console.error, and add error handler property on vd-board
Browse files Browse the repository at this point in the history
  • Loading branch information
johnson86tw committed Dec 21, 2022
1 parent 3073439 commit 5028f30
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 14 deletions.
11 changes: 10 additions & 1 deletion demo/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ watch(selectedChainId, async (val, oldVal) => {
console.error(e)
}
})
const connectErrorHandler = (error: any) => {
console.error('Connect error: ', error)
}
</script>

<template>
Expand Down Expand Up @@ -165,7 +169,12 @@ watch(selectedChainId, async (val, oldVal) => {
</div>
</div>

<vd-board v-if="connectorsCreated" :connectors="connectors" dark>
<vd-board
v-if="connectorsCreated"
:connectors="connectors"
:connectErrorHandler="connectErrorHandler"
dark
>
<!-- <template #loading>
<div v-if="wallet.status === 'loading'"></div>
</template> -->
Expand Down
19 changes: 14 additions & 5 deletions src/components/Board.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ export default defineComponent({
required: false,
default: false,
},
connectErrorHandler: {
type: Function,
required: false,
default: undefined,
},
autoConnectErrorHandler: {
type: Function,
required: false,
default: undefined,
},
},
setup(props) {
const { boardOpen, close } = useBoard()
Expand All @@ -49,9 +59,8 @@ export default defineComponent({
try {
isAutoConnecting.value = true
await autoConnect(connectors)
} catch (err) {
console.error(err)
return
} catch (err: any) {
props.autoConnectErrorHandler && props.autoConnectErrorHandler(err)
} finally {
isAutoConnecting.value = false
}
Expand All @@ -62,8 +71,8 @@ export default defineComponent({
try {
close()
await connectWith(connector)
} catch (err) {
console.error(err)
} catch (err: any) {
props.connectErrorHandler && props.connectErrorHandler(err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/composables/useEthers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ async function activate(externalProvider: ExternalProvider) {
try {
const _balance = await signer?.value.getBalance()
balance.value = _balance.toBigInt()
} catch (e) {
console.error(e)
} catch (error: any) {
throw new Error('Failed to update balance')
}
}, interval)
}
Expand Down
5 changes: 3 additions & 2 deletions src/composables/useMulticall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ export function useMulticall(provider: Web3Provider | JsonRpcProvider) {
)

results.value = returnData.map((data, i) => {
if (!data.success)
console.error(`Failed to call ${contractCalls[i].method}`)
if (!data.success) {
throw new Error(`Failed to call ${contractCalls[i].method}`)
}
const iface = getInterface(contractCalls[i].interface)
return iface.decodeFunctionResult(
contractCalls[i].method,
Expand Down
2 changes: 1 addition & 1 deletion src/composables/useWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export function useWallet(options: useWalletOptions = { useEthers: true }) {
await connectWith(safe)
}
} catch (err: any) {
console.error(err) // let keep processing the following code
throw new Error('Failed to connect Gnosis Safe') // let keep processing the following code
}
}

Expand Down
1 change: 0 additions & 1 deletion src/connectors/walletConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export class WalletConnectConnector extends Connector<
return new Promise<WalletConnectProvider>(async (resolve, reject) => {
provider.wc.on('disconnect', (err, payload) => {
if (!provider.connected) {
console.error(err, payload)
reject(new UserRejectedRequestError(err))
}
})
Expand Down
3 changes: 1 addition & 2 deletions src/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export function displayEther(balance: BigNumber | bigint, fixed = 2) {

export function displayChainName(chainId: number) {
if (!checkChainId(chainId)) {
console.error('Error: Invalid chainId')
return 'network not found'
return ''
}
const { availableNetworks } = useEthers()
return availableNetworks.value[chainId].chainName.toLowerCase()
Expand Down

0 comments on commit 5028f30

Please sign in to comment.