Skip to content

Commit

Permalink
fix: watch isActivated for the onActivatedHook
Browse files Browse the repository at this point in the history
  • Loading branch information
johnson86tw committed Oct 16, 2022
1 parent a821e84 commit dcf0c9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 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
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 dcf0c9a

Please sign in to comment.