added correct resolving of account positions (#270)
This commit is contained in:
parent
415da05b8d
commit
9007e31707
@ -1,13 +1,24 @@
|
||||
import { getCreditManagerQueryClient } from 'api/cosmwasm-client'
|
||||
import { BNCoin } from 'types/classes/BNCoin'
|
||||
import { Positions } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
|
||||
|
||||
export default async function getAccount(accountId: string): Promise<Positions> {
|
||||
export default async function getAccount(accountId: string): Promise<Account> {
|
||||
const creditManagerQueryClient = await getCreditManagerQueryClient()
|
||||
|
||||
const account = creditManagerQueryClient.positions({ accountId })
|
||||
const accountPosition: Positions = await creditManagerQueryClient.positions({ accountId })
|
||||
|
||||
if (account) {
|
||||
return account
|
||||
if (accountPosition) {
|
||||
const debts = accountPosition.debts.map((debt) => new BNCoin(debt))
|
||||
const lends = accountPosition.lends.map((lend) => new BNCoin(lend))
|
||||
const deposits = accountPosition.deposits.map((deposit) => new BNCoin(deposit))
|
||||
|
||||
return {
|
||||
id: accountPosition.account_id,
|
||||
debts,
|
||||
deposits,
|
||||
lends,
|
||||
vaults: accountPosition.vaults,
|
||||
}
|
||||
}
|
||||
|
||||
return new Promise((_, reject) => reject('No account found'))
|
||||
|
@ -5,7 +5,7 @@ export default async function getAccountDebts(accountId: string): Promise<BNCoin
|
||||
const account = await getAccount(accountId)
|
||||
|
||||
if (account) {
|
||||
return account.debts.map((coin) => new BNCoin(coin))
|
||||
return account.debts
|
||||
}
|
||||
|
||||
return new Promise((_, reject) => reject('Account not found'))
|
||||
|
@ -5,7 +5,7 @@ export default async function getAccountDeposits(accountId: string): Promise<BNC
|
||||
const account = await getAccount(accountId)
|
||||
|
||||
if (account) {
|
||||
return account.deposits.map((coin) => new BNCoin(coin))
|
||||
return account.deposits
|
||||
}
|
||||
|
||||
return new Promise((_, reject) => reject('Account not found'))
|
||||
|
@ -62,11 +62,12 @@ export default function ConnectedButton() {
|
||||
|
||||
useEffect(() => {
|
||||
if (!walletBalances || walletBalances.length === 0) return
|
||||
setWalletAmount(
|
||||
BigNumber(
|
||||
walletBalances?.find((coin: Coin) => coin.denom === baseAsset.denom)?.amount ?? 0,
|
||||
).div(10 ** baseAsset.decimals),
|
||||
)
|
||||
const newAmount = BigNumber(
|
||||
walletBalances?.find((coin: Coin) => coin.denom === baseAsset.denom)?.amount ?? 0,
|
||||
).div(10 ** baseAsset.decimals)
|
||||
|
||||
if (walletAmount.isEqualTo(newAmount)) return
|
||||
setWalletAmount(newAmount)
|
||||
|
||||
const assetDenoms = marketAssets.map((asset) => asset.denom)
|
||||
const balances = walletBalances.filter((coin) => assetDenoms.includes(coin.denom))
|
||||
|
Loading…
Reference in New Issue
Block a user