diff --git a/src/api/accounts/getAccount.ts b/src/api/accounts/getAccount.ts index 9b85579a..ffb6eb13 100644 --- a/src/api/accounts/getAccount.ts +++ b/src/api/accounts/getAccount.ts @@ -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 { +export default async function getAccount(accountId: string): Promise { 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')) diff --git a/src/api/accounts/getAccountDebts.ts b/src/api/accounts/getAccountDebts.ts index 7439fcce..037c0b2a 100644 --- a/src/api/accounts/getAccountDebts.ts +++ b/src/api/accounts/getAccountDebts.ts @@ -5,7 +5,7 @@ export default async function getAccountDebts(accountId: string): Promise new BNCoin(coin)) + return account.debts } return new Promise((_, reject) => reject('Account not found')) diff --git a/src/api/accounts/getAccountDeposits.ts b/src/api/accounts/getAccountDeposits.ts index a3322269..a476290c 100644 --- a/src/api/accounts/getAccountDeposits.ts +++ b/src/api/accounts/getAccountDeposits.ts @@ -5,7 +5,7 @@ export default async function getAccountDeposits(accountId: string): Promise new BNCoin(coin)) + return account.deposits } return new Promise((_, reject) => reject('Account not found')) diff --git a/src/components/Wallet/ConnectedButton.tsx b/src/components/Wallet/ConnectedButton.tsx index 939e2868..0ee1c4b4 100644 --- a/src/components/Wallet/ConnectedButton.tsx +++ b/src/components/Wallet/ConnectedButton.tsx @@ -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))