vault balance tracking
This commit is contained in:
@@ -13,26 +13,34 @@ export function onChainChanged(chainId) {
|
||||
store.chainId = chainId
|
||||
store.account = null
|
||||
provider = new ethers.BrowserProvider(window.ethereum, chainId)
|
||||
provider.listAccounts().then(onAccountsChanged)
|
||||
provider.listAccounts().then(changeAccounts)
|
||||
new ethers.Interface([
|
||||
// 'event DexorderSwapCreated' // todo
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
function onAccountsChanged(accounts) {
|
||||
// console.log('accounts changed', accounts)
|
||||
const store = useStore()
|
||||
function changeAccounts(accounts) {
|
||||
if( accounts.length === 0 ) {
|
||||
store.account = null
|
||||
store.vaults = []
|
||||
store.vaultBalances = {}
|
||||
}
|
||||
else if (accounts[0] !== store.account) {
|
||||
else {
|
||||
const store = useStore()
|
||||
store.account = accounts[0].address
|
||||
flushOrders()
|
||||
socket.emit('address', store.chainId, accounts[0].address)
|
||||
}
|
||||
}
|
||||
|
||||
function onAccountsChanged(accounts) {
|
||||
// console.log('accounts changed', accounts)
|
||||
const store = useStore()
|
||||
if (accounts.length === 0 || accounts[0] !== store.account)
|
||||
changeAccounts(store, accounts);
|
||||
}
|
||||
|
||||
export async function watchWallet() {
|
||||
const chainId = (await new ethers.BrowserProvider(window.ethereum).getNetwork()).chainId
|
||||
onChainChanged(chainId)
|
||||
|
||||
Reference in New Issue
Block a user