vault balance tracking
This commit is contained in:
@@ -13,26 +13,34 @@ export function onChainChanged(chainId) {
|
|||||||
store.chainId = chainId
|
store.chainId = chainId
|
||||||
store.account = null
|
store.account = null
|
||||||
provider = new ethers.BrowserProvider(window.ethereum, chainId)
|
provider = new ethers.BrowserProvider(window.ethereum, chainId)
|
||||||
provider.listAccounts().then(onAccountsChanged)
|
provider.listAccounts().then(changeAccounts)
|
||||||
new ethers.Interface([
|
new ethers.Interface([
|
||||||
// 'event DexorderSwapCreated' // todo
|
// 'event DexorderSwapCreated' // todo
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onAccountsChanged(accounts) {
|
function changeAccounts(accounts) {
|
||||||
// console.log('accounts changed', accounts)
|
|
||||||
const store = useStore()
|
|
||||||
if( accounts.length === 0 ) {
|
if( accounts.length === 0 ) {
|
||||||
store.account = null
|
store.account = null
|
||||||
|
store.vaults = []
|
||||||
|
store.vaultBalances = {}
|
||||||
}
|
}
|
||||||
else if (accounts[0] !== store.account) {
|
else {
|
||||||
|
const store = useStore()
|
||||||
store.account = accounts[0].address
|
store.account = accounts[0].address
|
||||||
flushOrders()
|
flushOrders()
|
||||||
socket.emit('address', store.chainId, accounts[0].address)
|
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() {
|
export async function watchWallet() {
|
||||||
const chainId = (await new ethers.BrowserProvider(window.ethereum).getNetwork()).chainId
|
const chainId = (await new ethers.BrowserProvider(window.ethereum).getNetwork()).chainId
|
||||||
onChainChanged(chainId)
|
onChainChanged(chainId)
|
||||||
|
|||||||
@@ -31,11 +31,10 @@ socket.on('p', async (pool, price) => {
|
|||||||
s.$patch({poolPrices: prices})
|
s.$patch({poolPrices: prices})
|
||||||
})
|
})
|
||||||
|
|
||||||
socket.on('vb', async (vault, token, balance) => {
|
socket.on('vb', async (vault, balances) => {
|
||||||
const s = useStore()
|
const s = useStore()
|
||||||
const balances = {}
|
console.log('vb', vault, balances)
|
||||||
balances[vault] = {}
|
const vb = JSON.parse(balances)
|
||||||
balances[vault][token] = balance
|
s.$patch({vaultBalances:vb})
|
||||||
s.$patch({vaultBalances: balances})
|
console.log('vault balances', vault, vb)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user