Skip to content

Commit

Permalink
Merge pull request #87 from chnejohnson/dev
Browse files Browse the repository at this point in the history
Fix some
  • Loading branch information
johnson86tw committed Oct 21, 2022
2 parents 650b021 + 7dd5d5d commit 977a562
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
1 change: 0 additions & 1 deletion demo/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
displayChainName,
displayEther,
shortenAddress,
ChainId,
useEthersHooks,
MetaMaskConnector,
WalletConnectConnector,
Expand Down
11 changes: 11 additions & 0 deletions demo/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ app.use(VueDapp, {
symbol: 'MATIC',
},
},
42161: {
chainId: ethers.utils.hexValue(42161),
blockExplorerUrls: ['https://arbiscan.io'],
chainName: 'Arbitrum One',
rpcUrls: ['https://arb1.arbitrum.io/rpc'],
nativeCurrency: {
name: 'Arbitrum',
symbol: 'ETH',
decimals: 18,
},
},
})

app.mount('#app')
8 changes: 6 additions & 2 deletions src/composables/useEthers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ async function activate(externalProvider: ExternalProvider) {
const updateBalance = async (interval: number = 10000) => {
updateBalanceInterval = setInterval(async () => {
if (!signer.value) return
const _balance = await signer?.value.getBalance()
balance.value = _balance.toBigInt()
try {
const _balance = await signer?.value.getBalance()
balance.value = _balance.toBigInt()
} catch (e) {
console.error(e)
}
}, interval)
}

Expand Down
14 changes: 9 additions & 5 deletions src/composables/useEthersHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,28 @@ export type OnActivatedHook = (context: EthersHooksContext) => void
export type OnChangedHook = (context: EthersHooksContext) => void
export type OnDeactivatedHook = () => void

const { provider, signer, network, address, balance } = useEthers()
const { provider, signer, network, address, balance, isActivated } = useEthers()

export function useEthersHooks() {
const onActivatedHook = ref<OnActivatedHook | null>(null)
const onDeactivatedHook = ref<OnDeactivatedHook | null>(null)
const onChangedHook = ref<OnChangedHook | null>(null)

watch(provider, (provider, oldProvider) => {
if (!oldProvider && provider) {
watch(isActivated, (val, oldVal) => {
if (!oldVal && val) {
onActivatedHook.value &&
onActivatedHook.value({
provider,
provider: provider.value!,
signer: signer.value!,
network: network.value!,
address: address.value,
balance: balance.value,
})
} else if (oldProvider && provider) {
}
})

watch(provider, (provider, oldProvider) => {
if (oldProvider && provider) {
onChangedHook.value &&
onChangedHook.value({
provider,
Expand Down

0 comments on commit 977a562

Please sign in to comment.