wallet connection fixes
This commit is contained in:
@@ -3,8 +3,6 @@ import {defineStore} from 'pinia'
|
||||
import {knownTokens} from "@/knownTokens.js";
|
||||
import {computed, ref} from "vue";
|
||||
import {version} from "@/version.js";
|
||||
import {ethers} from "ethers";
|
||||
import {updateAccounts} from "@/blockchain/wallet.js";
|
||||
|
||||
// USING THE STORE:
|
||||
//
|
||||
@@ -70,9 +68,9 @@ export const useStore = defineStore('app', ()=> {
|
||||
_chainId.value = v
|
||||
account.value = null
|
||||
}
|
||||
if (changed || _provider.value === null) {
|
||||
if (changed || providerRef.value === null) {
|
||||
console.log('invalidating provider')
|
||||
_provider.value = UNKNOWN_PROVIDER
|
||||
providerRef.value = UNKNOWN_PROVIDER
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -82,22 +80,8 @@ export const useStore = defineStore('app', ()=> {
|
||||
})
|
||||
const chain = computed(() => !_chainId.value ? null : (_chainInfo.value[_chainId.value] || null))
|
||||
// this provider is for the app's chainId not the wallet's chainId.
|
||||
let _provider = UNKNOWN_PROVIDER // null indicates a known-unavailable provider whereas undefined means provider status is unknown
|
||||
const provider = computed(()=>{
|
||||
if (_provider===UNKNOWN_PROVIDER) {
|
||||
// unknown provider status
|
||||
try {
|
||||
_provider = new ethers.BrowserProvider(window.ethereum, _chainId.value);
|
||||
updateAccounts(_chainId.value, _provider)
|
||||
}
|
||||
catch (e) {
|
||||
console.error('could not get provider', _chainId.value, e)
|
||||
_provider = null
|
||||
}
|
||||
}
|
||||
// if _provider is null then it is known to be an unavailable chain
|
||||
return _provider
|
||||
})
|
||||
const providerRef = ref(null)
|
||||
const provider = computed(()=>providerRef.value)
|
||||
const vaultInitCodeHash = computed(() => !chain.value ? null : chain.value.vaultInitCodeHash)
|
||||
const account = ref(null)
|
||||
const vaults = ref([])
|
||||
@@ -140,8 +124,8 @@ export const useStore = defineStore('app', ()=> {
|
||||
setInterval(()=>clock.value=timestamp(), 10*1000)
|
||||
|
||||
return {
|
||||
nav, chainId, chainInfo, chain, provider, vaultInitCodeHash, account, vaults, transactionSenders, errors,
|
||||
extraTokens, poolPrices, vaultBalances, orders, vault, tokens, factory, helper, mockenv, mockCoins,
|
||||
nav, chainId, chainInfo, chain, provider, providerRef, vaultInitCodeHash, account, vaults, transactionSenders,
|
||||
errors, extraTokens, poolPrices, vaultBalances, orders, vault, tokens, factory, helper, mockenv, mockCoins,
|
||||
removeTransactionSender, error, closeError, addToken, clock, balances,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user