Skip to content

Commit

Permalink
Merge pull request #74 from re2005/main
Browse files Browse the repository at this point in the history
fix: clear interval when disconnect or network switch
  • Loading branch information
re2005 committed Aug 16, 2022
2 parents 1f18c23 + 53ab6cc commit c357bd9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/composables/useEthers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ const network = ref<Network | null>(null)
const address = ref('')
const dnsAlias = ref('')
const balance = ref<bigint>(BigInt(0))
let updateBalanceInterval: any

const deactivate = () => {
clearInterval(updateBalanceInterval)
isActivated.value = false
provider.value = null
signer.value = null
Expand Down Expand Up @@ -79,8 +81,9 @@ async function activate(externalProvider: ExternalProvider) {
// Put it outside the timer as the lookup method can occasionally take longer than 5000ms
dnsAlias.value = await lookupDNS(_network?.chainId, _address)

clearInterval(updateBalanceInterval)
const updateBalance = async (interval: number = 10000) => {
setInterval(async () => {
updateBalanceInterval = setInterval(async () => {
if (!signer.value) return
const _balance = await signer?.value.getBalance()
balance.value = _balance.toBigInt()
Expand Down

0 comments on commit c357bd9

Please sign in to comment.