From 46d4113d98f5d06ecfc8aa8fece657c690ff8986 Mon Sep 17 00:00:00 2001 From: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com> Date: Tue, 5 Sep 2023 12:45:55 +0200 Subject: [PATCH] Scope Funding to actions, enable fund for USDC (and others) (#426) * fix vault test and vaulttable pos value * fix vault test and vaulttable pos value updated * Scope lend for deposit to action only * fix build error * fix build error --- __tests__/utils/vaults.test.ts | 15 +++++++-------- src/api/vaults/getDepositedVaults.ts | 14 ++++++++++---- src/components/Account/AccountFund.tsx | 8 ++++++-- src/components/Account/AccountMenuContent.tsx | 14 ++++++++++++-- src/components/Earn/Farm/VaultTable.tsx | 7 ++++--- src/components/Modals/BorrowModal.tsx | 2 +- .../Modals/FundWithdraw/FundAccount.tsx | 17 ++++++++++++----- src/components/Switch/SwitchAutoLend.tsx | 14 +++++++++++--- src/components/Switch/SwitchWithLabel.tsx | 13 +++++++++++-- src/constants/assets.ts | 5 ++++- src/store/slices/broadcast.ts | 13 ++++++++----- src/types/interfaces/store/broadcast.d.ts | 4 ++-- src/utils/tokens.ts | 7 +------ src/utils/vaults.ts | 14 +++++++------- 14 files changed, 96 insertions(+), 51 deletions(-) diff --git a/__tests__/utils/vaults.test.ts b/__tests__/utils/vaults.test.ts index 960698d9..21e33a02 100644 --- a/__tests__/utils/vaults.test.ts +++ b/__tests__/utils/vaults.test.ts @@ -22,13 +22,12 @@ describe('getVaultMetaData()', () => { expect(getVaultMetaData(testAddress)?.name).toBe(testVaultName) }) - // TODO: Update the following test suite accordingly after new testnet vaults placed in constants - // it('returns the TESTNET vault of given address WHEN environment configured to testnet', () => { - // jest.spyOn(constants, 'IS_TESTNET', 'get').mockReturnValue(true) + it('returns the TESTNET vault of given address WHEN environment configured to testnet', () => { + jest.spyOn(constants, 'IS_TESTNET', 'get').mockReturnValue(true) - // const testAddress = 'osmo1q40xvrzpldwq5he4ftsf7zm2jf80tj373qaven38yqrvhex8r9rs8n94kv' - // const testVaultName = 'OSMO-USDC.n' + const testAddress = 'osmo1m45ap4rq4m2mfjkcqu9ks9mxmyx2hvx0cdca9sjmrg46q7lghzqqhxxup5' + const testVaultName = 'OSMO-ATOM' - // expect(getVaultMetaData(testAddress)?.name).toBe(testVaultName) - // }) -}) + expect(getVaultMetaData(testAddress)?.name).toBe(testVaultName) + }) +}) \ No newline at end of file diff --git a/src/api/vaults/getDepositedVaults.ts b/src/api/vaults/getDepositedVaults.ts index 5eaa672a..2c88b11d 100644 --- a/src/api/vaults/getDepositedVaults.ts +++ b/src/api/vaults/getDepositedVaults.ts @@ -3,13 +3,15 @@ import moment from 'moment' import { getClient, getCreditManagerQueryClient, getVaultQueryClient } from 'api/cosmwasm-client' import getPrice from 'api/prices/getPrice' import getVaults from 'api/vaults/getVaults' +import { BN_ZERO } from 'constants/math' +import { BNCoin } from 'types/classes/BNCoin' import { VaultStatus } from 'types/enums/vault' import { VaultPosition, VaultPositionAmount, } from 'types/generated/mars-credit-manager/MarsCreditManager.types' +import { getCoinValue } from 'utils/formatters' import { BN } from 'utils/helpers' -import { BN_ZERO } from 'constants/math' async function getUnlocksAtTimestamp(unlockingId: number, vaultAddress: string) { try { @@ -130,8 +132,12 @@ async function getVaultValuesAndAmounts( secondary: BN(secondaryLpToken.amount), }, values: { - primary: BN(primaryLpToken.amount).multipliedBy(primaryPrice), - secondary: BN(secondaryLpToken.amount).multipliedBy(secondaryPrice), + primary: getCoinValue(new BNCoin(primaryLpToken), [ + BNCoin.fromDenomAndBigNumber(primaryLpToken.denom, primaryPrice), + ]), + secondary: getCoinValue(new BNCoin(secondaryLpToken), [ + BNCoin.fromDenomAndBigNumber(secondaryLpToken.denom, secondaryPrice), + ]), }, } } catch (ex) { @@ -173,4 +179,4 @@ async function getDepositedVaults(accountId: string): Promise } } -export default getDepositedVaults +export default getDepositedVaults \ No newline at end of file diff --git a/src/components/Account/AccountFund.tsx b/src/components/Account/AccountFund.tsx index 71d4f515..3f8b1357 100644 --- a/src/components/Account/AccountFund.tsx +++ b/src/components/Account/AccountFund.tsx @@ -40,6 +40,7 @@ export default function AccountFund() { const hasFundingAssets = fundingAssets.length > 0 && fundingAssets.every((a) => a.toCoin().amount !== '0') const { data: marketAssets } = useMarketAssets() + const [isLending, toggleIsLending] = useToggle(false) const baseBalance = useMemo( () => walletBalances.find(byDenom(baseAsset.denom))?.amount ?? '0', @@ -58,10 +59,11 @@ export default function AccountFund() { const result = await deposit({ accountId, coins: fundingAssets, + lend: isLending, }) setIsFunding(false) if (result) useStore.setState({ focusComponent: null, walletAssetsModal: null }) - }, [fundingAssets, accountId, setIsFunding, deposit]) + }, [setIsFunding, accountId, deposit, fundingAssets, isLending]) const handleSelectAssetsClick = useCallback(() => { useStore.setState({ @@ -174,6 +176,8 @@ export default function AccountFund() {