From 44ca57b1eee2460d52bf18101981e9148f029e90 Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 11 May 2023 15:13:08 +0200 Subject: [PATCH 01/12] fix(loans): display correct incentive rewards --- package.json | 2 +- .../LoanPositionsTable/LoanPositionsTable.tsx | 10 ++++++---- .../components/BorrowAssetsTable/BorrowAssetsTable.tsx | 9 ++++++--- .../components/LendAssetsTable/LendAssetsTable.tsx | 9 ++++++--- .../components/LoansInsights/LoansInsights.tsx | 8 ++++---- .../api/loans/use-get-account-lending-statistics.tsx | 9 ++++++++- .../api/loans/use-get-account-subsidy-rewards.tsx | 4 ++-- yarn.lock | 8 ++++---- 8 files changed, 37 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 3455fb1b58..85afb29484 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "@headlessui/react": "^1.1.1", "@heroicons/react": "^2.0.0", "@interlay/bridge": "^0.2.4", - "@interlay/interbtc-api": "2.1.1", + "@interlay/interbtc-api": "2.2.1", "@interlay/monetary-js": "0.7.2", "@polkadot/api": "9.14.2", "@polkadot/extension-dapp": "0.44.1", diff --git a/src/components/LoanPositionsTable/LoanPositionsTable.tsx b/src/components/LoanPositionsTable/LoanPositionsTable.tsx index 5dd60b7919..f50d1df43c 100644 --- a/src/components/LoanPositionsTable/LoanPositionsTable.tsx +++ b/src/components/LoanPositionsTable/LoanPositionsTable.tsx @@ -7,6 +7,7 @@ import { convertMonetaryAmountToValueInUSD } from '@/common/utils/utils'; import { Switch } from '@/component-library'; import { LoanType } from '@/types/loans'; import { getTokenPrice } from '@/utils/helpers/prices'; +import { useGetAccountSubsidyRewards } from '@/utils/hooks/api/loans/use-get-account-subsidy-rewards'; import { useGetPrices } from '@/utils/hooks/api/use-get-prices'; import { AssetCell, BalanceCell, Table, TableProps } from '../DataGrid'; @@ -52,6 +53,7 @@ const LoanPositionsTable = ({ const titleId = useId(); const { t } = useTranslation(); const prices = useGetPrices(); + const { data: subsidyRewards } = useGetAccountSubsidyRewards(); const isLending = variant === 'lend'; const showCollateral = !!onPressCollateralSwitch && isLending; @@ -84,13 +86,13 @@ const LoanPositionsTable = ({ const { currency } = amountProp; const asset = ; - const { borrowApy, borrowReward, lendApy, lendReward } = assets[currency.ticker]; + const { borrowApy, lendApy } = assets[currency.ticker]; const apyCellProps = isLending - ? { apy: lendApy, rewards: lendReward } + ? { apy: lendApy, rewards: subsidyRewards ? subsidyRewards.perMarket[currency.ticker].lend : null } : { apy: borrowApy, - rewards: borrowReward, + rewards: subsidyRewards ? subsidyRewards.perMarket[currency.ticker].borrow : null, accumulatedDebt: (position as BorrowPosition).accumulatedDebt, isBorrow: true }; @@ -133,7 +135,7 @@ const LoanPositionsTable = ({ collateral }; }), - [assets, isLending, onPressCollateralSwitch, onRowAction, positions, prices, showCollateral] + [assets, isLending, onPressCollateralSwitch, onRowAction, positions, prices, showCollateral, subsidyRewards] ); return ( diff --git a/src/pages/Loans/LoansOverview/components/BorrowAssetsTable/BorrowAssetsTable.tsx b/src/pages/Loans/LoansOverview/components/BorrowAssetsTable/BorrowAssetsTable.tsx index e81e132de8..d055d959cd 100644 --- a/src/pages/Loans/LoansOverview/components/BorrowAssetsTable/BorrowAssetsTable.tsx +++ b/src/pages/Loans/LoansOverview/components/BorrowAssetsTable/BorrowAssetsTable.tsx @@ -8,6 +8,7 @@ import { Cell, Table, TableProps } from '@/components'; import { ApyCell } from '@/components/LoanPositionsTable/ApyCell'; import { LoanTablePlaceholder } from '@/components/LoanPositionsTable/LoanTablePlaceholder'; import { getTokenPrice } from '@/utils/helpers/prices'; +import { useGetAccountSubsidyRewards } from '@/utils/hooks/api/loans/use-get-account-subsidy-rewards'; import { useGetPrices } from '@/utils/hooks/api/use-get-prices'; import { StyledAssetCell } from './BorrowAssetsTable.style'; @@ -47,17 +48,19 @@ const BorrowAssetsTable = ({ assets, onRowAction, ...props }: BorrowAssetsTableP const titleId = useId(); const { t } = useTranslation(); const prices = useGetPrices(); + const { data: subsidyRewards } = useGetAccountSubsidyRewards(); const rows: BorrowAssetsTableRow[] = useMemo( () => - Object.values(assets).map(({ borrowApy, currency, availableCapacity, borrowReward, totalBorrows }) => { + Object.values(assets).map(({ borrowApy, currency, availableCapacity, totalBorrows }) => { const asset = ; + const reward = subsidyRewards ? subsidyRewards.perMarket[currency.ticker].borrow : null; const apy = ( - Object.values(assets).map(({ lendApy, lendReward, currency, totalLiquidity }) => { + Object.values(assets).map(({ lendApy, currency, totalLiquidity }) => { const asset = ; + const reward = subsidyRewards ? subsidyRewards.perMarket[currency.ticker].lend : null; const apy = ( onRowAction?.(currency.ticker as Key)} @@ -83,7 +86,7 @@ const LendAssetsTable = ({ assets, onRowAction, ...props }: LendAssetsTableProps totalSupply }; }), - [assets, balances, onRowAction, prices] + [assets, balances, onRowAction, prices, subsidyRewards] ); return ( diff --git a/src/pages/Loans/LoansOverview/components/LoansInsights/LoansInsights.tsx b/src/pages/Loans/LoansOverview/components/LoansInsights/LoansInsights.tsx index 7e8f2d7f0f..1d62c7c1a5 100644 --- a/src/pages/Loans/LoansOverview/components/LoansInsights/LoansInsights.tsx +++ b/src/pages/Loans/LoansOverview/components/LoansInsights/LoansInsights.tsx @@ -42,11 +42,11 @@ const LoansInsights = ({ statistics }: LoansInsightsProps): JSX.Element => { const netPercentage = formatPercentage(netAPY?.toNumber() || 0); const netPercentageLabel = `${netAPY?.gt(0) ? '+' : ''}${netPercentage}`; - const subsidyRewardsAmount = formatNumber(subsidyRewards?.toBig().toNumber() || 0, { - maximumFractionDigits: subsidyRewards?.currency.humanDecimals || 5 + const subsidyRewardsAmount = formatNumber(subsidyRewards?.total.toBig().toNumber() || 0, { + maximumFractionDigits: subsidyRewards?.total.currency.humanDecimals || 5 }); - const subsidyRewardsAmountLabel = `${subsidyRewardsAmount} ${subsidyRewards?.currency.ticker || ''}`; - const hasSubsidyRewards = !!subsidyRewards && !subsidyRewards?.isZero(); + const subsidyRewardsAmountLabel = `${subsidyRewardsAmount} ${subsidyRewards?.total.currency.ticker || ''}`; + const hasSubsidyRewards = !!subsidyRewards && !subsidyRewards?.total.isZero(); return ( <> diff --git a/src/utils/hooks/api/loans/use-get-account-lending-statistics.tsx b/src/utils/hooks/api/loans/use-get-account-lending-statistics.tsx index b9211bba93..0aa6d77d05 100644 --- a/src/utils/hooks/api/loans/use-get-account-lending-statistics.tsx +++ b/src/utils/hooks/api/loans/use-get-account-lending-statistics.tsx @@ -122,7 +122,14 @@ const useGetAccountLendingStatistics = (): UseGetAccountLendingStatistics => { return undefined; } - return getAccountPositionsStats(loanAssets, lendPositions, borrowPositions, subsidyRewards, prices, lendingStats); + return getAccountPositionsStats( + loanAssets, + lendPositions, + borrowPositions, + subsidyRewards.total, + prices, + lendingStats + ); }, [lendPositions, borrowPositions, prices, subsidyRewards, loanAssets, lendingStats]); return { diff --git a/src/utils/hooks/api/loans/use-get-account-subsidy-rewards.tsx b/src/utils/hooks/api/loans/use-get-account-subsidy-rewards.tsx index c373f8647a..3e8df5b571 100644 --- a/src/utils/hooks/api/loans/use-get-account-subsidy-rewards.tsx +++ b/src/utils/hooks/api/loans/use-get-account-subsidy-rewards.tsx @@ -1,4 +1,4 @@ -import { CurrencyExt } from '@interlay/interbtc-api'; +import { AccruedRewards, CurrencyExt } from '@interlay/interbtc-api'; import { MonetaryAmount } from '@interlay/monetary-js'; import { AccountId } from '@polkadot/types/interfaces'; import { useErrorHandler } from 'react-error-boundary'; @@ -9,7 +9,7 @@ import { BLOCKTIME_REFETCH_INTERVAL } from '@/utils/constants/api'; import useAccountId from '../../use-account-id'; interface AccountAccruedRewards { - data: MonetaryAmount | undefined; + data: AccruedRewards | undefined; refetch: () => void; } diff --git a/yarn.lock b/yarn.lock index e602efd82e..453b4c1b69 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2073,10 +2073,10 @@ dependencies: axios "^0.21.1" -"@interlay/interbtc-api@2.1.1": - version "2.1.1" - resolved "https://registry.yarnpkg.com/@interlay/interbtc-api/-/interbtc-api-2.1.1.tgz#cdbd4fab03b83b32a32936bfa3f7eaf5f55859f7" - integrity sha512-6cNPwgExJHQJhtxgAa3Igmswyfujz8e+EVxyj9IQHs1KtJydYZQpa0qQC/QnOiQqRXw4DVNZkmKLEfXodDLBdQ== +"@interlay/interbtc-api@2.2.1": + version "2.2.1" + resolved "https://registry.yarnpkg.com/@interlay/interbtc-api/-/interbtc-api-2.2.1.tgz#7babde28fdcc47ebd986405184602b95f61f4c29" + integrity sha512-0QY4sqB2SLrnIPVutvYFNtMdZ3BNO0VjvTYNizd63OUJlqfsgujpkp4dWzIO+DMC5kzkcEo80r2NloyJer7p2A== dependencies: "@interlay/esplora-btc-api" "0.4.0" "@interlay/interbtc-types" "1.12.0" From 4b9b5d47861ab9f9326e58331c5a7682f7c83bd0 Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 11 May 2023 15:16:13 +0200 Subject: [PATCH 02/12] test: update mock --- src/test/mocks/@interlay/interbtc-api/parachain/loans.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/test/mocks/@interlay/interbtc-api/parachain/loans.ts b/src/test/mocks/@interlay/interbtc-api/parachain/loans.ts index e29119298d..a1f8b7f0a7 100644 --- a/src/test/mocks/@interlay/interbtc-api/parachain/loans.ts +++ b/src/test/mocks/@interlay/interbtc-api/parachain/loans.ts @@ -126,7 +126,14 @@ const DEFAULT_ASSETS: TickerToData = { const mockGetLendPositionsOfAccount = jest.fn().mockReturnValue(DEFAULT_LEND_POSITIONS); const mockGetBorrowPositionsOfAccount = jest.fn().mockReturnValue(DEFAULT_BORROW_POSITIONS); const mockGetLoanAssets = jest.fn().mockReturnValue(DEFAULT_ASSETS); -const mockGetAccountSubsidyRewards = jest.fn().mockReturnValue(DEFAULT_INTR.MONETARY.MEDIUM); +const mockGetAccountSubsidyRewards = jest.fn().mockReturnValue({ + total: DEFAULT_INTR.MONETARY.MEDIUM, + perMarket: { + INTR: null, + IBTC: null, + DOT: null + } +}); const mockLend = jest.fn(); const mockWithdraw = jest.fn(); From b66e7a91ba736c687bf1fcbf6b41a1f34faa7635 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 12 May 2023 14:16:24 +0200 Subject: [PATCH 03/12] wip: add prices for qtokens --- src/utils/hooks/api/use-get-prices.tsx | 38 +++++++++++++++++++++----- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/utils/hooks/api/use-get-prices.tsx b/src/utils/hooks/api/use-get-prices.tsx index 73fd8df062..63b15cfd6f 100644 --- a/src/utils/hooks/api/use-get-prices.tsx +++ b/src/utils/hooks/api/use-get-prices.tsx @@ -1,8 +1,9 @@ -import { CurrencyExt, ForeignAsset } from '@interlay/interbtc-api'; +import { CurrencyExt, isForeignAsset, isLendToken, TickerToData } from '@interlay/interbtc-api'; import { Bitcoin } from '@interlay/monetary-js'; import { useEffect } from 'react'; import { useQuery } from 'react-query'; import { useSelector } from 'react-redux'; +import Big from 'big.js'; import { StoreType } from '@/common/types/util.types'; import { PRICES_API, REFETCH_INTERVAL } from '@/utils/constants/api'; @@ -10,9 +11,12 @@ import { COINGECKO_ID_BY_CURRENCY_TICKER } from '@/utils/constants/currency'; import { useGetCurrencies } from './use-get-currencies'; +// MEMO: Returns `undefined` for currencies without coingecko ID. const getCoingeckoId = (currency: CurrencyExt) => { - const asForeignAsset = currency as ForeignAsset; - return asForeignAsset.foreignAsset?.coingeckoId || COINGECKO_ID_BY_CURRENCY_TICKER[currency.ticker]; + if (isForeignAsset(currency)) { + return currency.foreignAsset.coingeckoId; + } + return COINGECKO_ID_BY_CURRENCY_TICKER[currency.ticker]; }; const composeIds = (currencies: CurrencyExt[]): string => @@ -31,9 +35,27 @@ const composeIds = (currencies: CurrencyExt[]): string => const composeEndpoint = (assetsIds: string): string => `${PRICES_API.URL}&ids=${assetsIds}`; -const getPricesByTicker = (currencies: CurrencyExt[], prices: Prices) => +const fetchPricesFromCoingecko = async (endpoint: string) => { + const response = await fetch(endpoint); + return response.json(); +}; + +const getPricesByTicker = (currencies: CurrencyExt[], prices: Prices, lendTokenPrices: TickerToData) => currencies.reduce((acc, currency) => { const coingeckoId = getCoingeckoId(currency); + + if (isLendToken(currency)) { + // MEMO: This works as long as lend tokens tickers + // are same as underlying currencies with only `q` character prepended. + const underlyingCurrencyTicker = currency.ticker.slice(1); + const underlyingToLendTokenRate = lendTokenPrices[underlyingCurrencyTicker].toNumber(); + // MEMO: Can be extended to different counter currencies later if needed. + const underlyingCurrencyPriceUSD = prices[underlyingCurrencyTicker].usd; + const lendTokenPrice = { usd: underlyingCurrencyPriceUSD / underlyingToLendTokenRate }; + + return { ...acc, [currency.ticker]: lendTokenPrice }; + } + return { ...acc, [currency.ticker]: prices[coingeckoId] }; }, {}); @@ -46,10 +68,12 @@ const getPrices = async (currencies?: CurrencyExt[]): Promise Date: Fri, 12 May 2023 16:58:02 +0200 Subject: [PATCH 04/12] fix: remove unused imports --- .eslintignore | 2 +- src/utils/hooks/api/loans/use-get-account-subsidy-rewards.tsx | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.eslintignore b/.eslintignore index d1441ab904..8bc7bc20b9 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,4 @@ node_modules build src/react-app-env.d.ts -api \ No newline at end of file +/api diff --git a/src/utils/hooks/api/loans/use-get-account-subsidy-rewards.tsx b/src/utils/hooks/api/loans/use-get-account-subsidy-rewards.tsx index 3e8df5b571..9be4fdf62c 100644 --- a/src/utils/hooks/api/loans/use-get-account-subsidy-rewards.tsx +++ b/src/utils/hooks/api/loans/use-get-account-subsidy-rewards.tsx @@ -1,5 +1,4 @@ -import { AccruedRewards, CurrencyExt } from '@interlay/interbtc-api'; -import { MonetaryAmount } from '@interlay/monetary-js'; +import { AccruedRewards } from '@interlay/interbtc-api'; import { AccountId } from '@polkadot/types/interfaces'; import { useErrorHandler } from 'react-error-boundary'; import { useQuery, useQueryClient } from 'react-query'; From 56bbe00a493c5f5f777e0a79a7c26dde3644d64d Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 15 May 2023 14:49:13 +0200 Subject: [PATCH 05/12] feat: add qTokens prices --- package.json | 2 +- src/utils/hooks/api/use-get-prices.tsx | 30 ++++++++++++++++++-------- yarn.lock | 8 +++---- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 85afb29484..cb12906fc4 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "@headlessui/react": "^1.1.1", "@heroicons/react": "^2.0.0", "@interlay/bridge": "^0.2.4", - "@interlay/interbtc-api": "2.2.1", + "@interlay/interbtc-api": "2.2.2", "@interlay/monetary-js": "0.7.2", "@polkadot/api": "9.14.2", "@polkadot/extension-dapp": "0.44.1", diff --git a/src/utils/hooks/api/use-get-prices.tsx b/src/utils/hooks/api/use-get-prices.tsx index 63b15cfd6f..d2030b66dc 100644 --- a/src/utils/hooks/api/use-get-prices.tsx +++ b/src/utils/hooks/api/use-get-prices.tsx @@ -40,22 +40,34 @@ const fetchPricesFromCoingecko = async (endpoint: string) => { return response.json(); }; +const getUnderlyingCurrencyFromLendToken = (currencies: CurrencyExt[], lendToken: CurrencyExt) => { + // MEMO: This works as long as lend tokens tickers + // are same as underlying currencies with only `q` character prepended. + const underlyingCurrencyTicker = lendToken.ticker.slice(1); + const underlyingCurrency = currencies.find(({ ticker }) => ticker === underlyingCurrencyTicker); + if (underlyingCurrency === undefined) { + throw new Error(`No underlying currency found for currency ${lendToken.name}`); + } + return underlyingCurrency; +}; + const getPricesByTicker = (currencies: CurrencyExt[], prices: Prices, lendTokenPrices: TickerToData) => currencies.reduce((acc, currency) => { - const coingeckoId = getCoingeckoId(currency); - if (isLendToken(currency)) { - // MEMO: This works as long as lend tokens tickers - // are same as underlying currencies with only `q` character prepended. - const underlyingCurrencyTicker = currency.ticker.slice(1); - const underlyingToLendTokenRate = lendTokenPrices[underlyingCurrencyTicker].toNumber(); - // MEMO: Can be extended to different counter currencies later if needed. - const underlyingCurrencyPriceUSD = prices[underlyingCurrencyTicker].usd; - const lendTokenPrice = { usd: underlyingCurrencyPriceUSD / underlyingToLendTokenRate }; + const underlyingCurrency = getUnderlyingCurrencyFromLendToken(currencies, currency); + const underlyingCurrencyCoingeckoId = getCoingeckoId(underlyingCurrency); + + const underlyingToLendTokenRate = lendTokenPrices[underlyingCurrency.ticker].toNumber(); + const underlyingCurrencyPriceUSD = prices[underlyingCurrencyCoingeckoId].usd; + const lendTokenPrice = { + // MEMO: Can be extended to different counter currencies later if needed. + usd: underlyingToLendTokenRate * underlyingCurrencyPriceUSD + }; return { ...acc, [currency.ticker]: lendTokenPrice }; } + const coingeckoId = getCoingeckoId(currency); return { ...acc, [currency.ticker]: prices[coingeckoId] }; }, {}); diff --git a/yarn.lock b/yarn.lock index 453b4c1b69..6e1717a6aa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2073,10 +2073,10 @@ dependencies: axios "^0.21.1" -"@interlay/interbtc-api@2.2.1": - version "2.2.1" - resolved "https://registry.yarnpkg.com/@interlay/interbtc-api/-/interbtc-api-2.2.1.tgz#7babde28fdcc47ebd986405184602b95f61f4c29" - integrity sha512-0QY4sqB2SLrnIPVutvYFNtMdZ3BNO0VjvTYNizd63OUJlqfsgujpkp4dWzIO+DMC5kzkcEo80r2NloyJer7p2A== +"@interlay/interbtc-api@2.2.2": + version "2.2.2" + resolved "https://registry.yarnpkg.com/@interlay/interbtc-api/-/interbtc-api-2.2.2.tgz#4803a80244abc9ef404dddefd265b9ece7ca859f" + integrity sha512-NuRjjIqeUPkt+aOTTmjMhx3TKAsL4id8kubiQsrAcyhsZnsnv/1bCXECzAWaZHVSi+XcxzfuoNLOxqrrx2+ISw== dependencies: "@interlay/esplora-btc-api" "0.4.0" "@interlay/interbtc-types" "1.12.0" From 9afbbf1e89813fb18cd8f00bdca008fd2266dd82 Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 15 May 2023 15:00:06 +0200 Subject: [PATCH 06/12] style: sort imports --- src/utils/hooks/api/use-get-prices.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/hooks/api/use-get-prices.tsx b/src/utils/hooks/api/use-get-prices.tsx index d2030b66dc..0e9cbb817f 100644 --- a/src/utils/hooks/api/use-get-prices.tsx +++ b/src/utils/hooks/api/use-get-prices.tsx @@ -1,9 +1,9 @@ import { CurrencyExt, isForeignAsset, isLendToken, TickerToData } from '@interlay/interbtc-api'; import { Bitcoin } from '@interlay/monetary-js'; +import Big from 'big.js'; import { useEffect } from 'react'; import { useQuery } from 'react-query'; import { useSelector } from 'react-redux'; -import Big from 'big.js'; import { StoreType } from '@/common/types/util.types'; import { PRICES_API, REFETCH_INTERVAL } from '@/utils/constants/api'; From b2b2ab29772512df024c966d22f3921e94671c3c Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 15 May 2023 15:24:08 +0200 Subject: [PATCH 07/12] test: add mock --- src/test/mocks/@interlay/interbtc-api/index.ts | 4 +++- src/test/mocks/@interlay/interbtc-api/parachain/loans.ts | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test/mocks/@interlay/interbtc-api/index.ts b/src/test/mocks/@interlay/interbtc-api/index.ts index 67650349f5..d454deca31 100644 --- a/src/test/mocks/@interlay/interbtc-api/index.ts +++ b/src/test/mocks/@interlay/interbtc-api/index.ts @@ -62,6 +62,7 @@ import { mockGetBorrowPositionsOfAccount, mockGetLendingStats, mockGetLendPositionsOfAccount, + mockGetLendTokenExchangeRates, mockGetLendTokens, mockGetLoanAssets, mockLend, @@ -137,7 +138,8 @@ const mockInterBtcApi: RecursivePartial = { enableAsCollateral: mockEnableAsCollateral, disableAsCollateral: mockDisableAsCollateral, claimAllSubsidyRewards: mockClaimAllSubsidyRewards, - getLendingStats: mockGetLendingStats + getLendingStats: mockGetLendingStats, + getLendTokenExchangeRates: mockGetLendTokenExchangeRates }, oracle: { getExchangeRate: mockOracleGetExchangeRate diff --git a/src/test/mocks/@interlay/interbtc-api/parachain/loans.ts b/src/test/mocks/@interlay/interbtc-api/parachain/loans.ts index a1f8b7f0a7..4e2651d8b9 100644 --- a/src/test/mocks/@interlay/interbtc-api/parachain/loans.ts +++ b/src/test/mocks/@interlay/interbtc-api/parachain/loans.ts @@ -135,6 +135,8 @@ const mockGetAccountSubsidyRewards = jest.fn().mockReturnValue({ } }); +const mockGetLendTokenExchangeRates = jest.fn(); + const mockLend = jest.fn(); const mockWithdraw = jest.fn(); const mockWithdrawAll = jest.fn(); @@ -203,6 +205,7 @@ export { mockGetBorrowPositionsOfAccount, mockGetLendingStats, mockGetLendPositionsOfAccount, + mockGetLendTokenExchangeRates, mockGetLoanAssets, mockLend, mockRepay, From ace95e60dd55beb9bd982db95b2c66e4c25a01d2 Mon Sep 17 00:00:00 2001 From: Thomas Jeatt Date: Tue, 16 May 2023 10:45:49 +0100 Subject: [PATCH 08/12] chore: revert copy change --- src/assets/locales/en/translation.json | 2 +- src/pages/Staking/BalancesUI/index.tsx | 2 +- src/pages/Staking/index.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/assets/locales/en/translation.json b/src/assets/locales/en/translation.json index e22cf946c5..439791e0dd 100644 --- a/src/assets/locales/en/translation.json +++ b/src/assets/locales/en/translation.json @@ -514,7 +514,7 @@ } }, "staking_page": { - "the_estimated_amount_of_governance_token_you_will_receive_as_rewards": "The estimated amount of {{governanceTokenSymbol}} per year you will receive as rewards. Depends on your proportion of the total {{voteGovernanceTokenSymbol}}.", + "the_estimated_amount_of_governance_token_you_will_receive_as_rewards": "The estimated amount of {{governanceTokenSymbol}} you will receive as rewards. Depends on your proportion of the total {{voteGovernanceTokenSymbol}}.", "new_vote_governance_token_gained": "New {{voteGovernanceTokenSymbol}} Gained", "the_increase_in_your_vote_governance_token_balance": "The increase in your {{voteGovernanceTokenSymbol}} balance", "total_vote_governance_token_in_the_network": "Total {{voteGovernanceTokenSymbol}} in the network", diff --git a/src/pages/Staking/BalancesUI/index.tsx b/src/pages/Staking/BalancesUI/index.tsx index 75334113dd..977e951896 100644 --- a/src/pages/Staking/BalancesUI/index.tsx +++ b/src/pages/Staking/BalancesUI/index.tsx @@ -92,7 +92,7 @@ const BalancesUI = ({ stakedAmount, voteStakedAmount, projectedRewardAmount }: P tokenSymbol={VOTE_GOVERNANCE_TOKEN_SYMBOL} /> { tooltip={`The APR may change as the amount of total ${VOTE_GOVERNANCE_TOKEN_SYMBOL} changes.`} /> Date: Tue, 16 May 2023 14:17:07 +0100 Subject: [PATCH 09/12] fix: fund wallet links --- src/components/FundWallet/FundWallet.tsx | 7 +++- src/components/FundWallet/use-entities.tsx | 42 ++++++++++++---------- src/config/links.ts | 11 +----- src/utils/constants/links.ts | 16 ++++++++- 4 files changed, 45 insertions(+), 31 deletions(-) diff --git a/src/components/FundWallet/FundWallet.tsx b/src/components/FundWallet/FundWallet.tsx index 08be16e11e..5dc156e1ad 100644 --- a/src/components/FundWallet/FundWallet.tsx +++ b/src/components/FundWallet/FundWallet.tsx @@ -58,7 +58,12 @@ const FundWallet = forwardRef( {description} {entities.map((entity, key) => ( - + {entity.icon} ))} diff --git a/src/components/FundWallet/use-entities.tsx b/src/components/FundWallet/use-entities.tsx index 38915363d7..e189dba8c6 100644 --- a/src/components/FundWallet/use-entities.tsx +++ b/src/components/FundWallet/use-entities.tsx @@ -1,5 +1,4 @@ import { ReactNode } from 'react'; -import { LinkProps } from 'react-router-dom'; import BANXA_INTERLAY from '@/assets/img/banxa-dark.png'; import BANXA_KITNSUGI from '@/assets/img/banxa-white.png'; @@ -11,14 +10,14 @@ import { ReactComponent as MexcLogoForInterlayIcon } from '@/assets/img/exchange import { ReactComponent as MexcLogoForKintsugiIcon } from '@/assets/img/exchanges/mexc-logo-for-kintsugi.svg'; import { ReactComponent as StellaSwapLogoIcon } from '@/assets/img/exchanges/stellaswap-logo.svg'; import { ReactComponent as ZenlinkLogoIcon } from '@/assets/img/exchanges/zenlink-logo.svg'; -import { BANXA_LINK, LINK_QUERY_PARAMETERS } from '@/config/links'; import { GOVERNANCE_TOKEN } from '@/config/relay-chains'; +import { EXTERNAL_PAGES, EXTERNAL_QUERY_PARAMETERS } from '@/utils/constants/links'; import { KUSAMA, POLKADOT } from '@/utils/constants/relay-chain-names'; import { useWallet } from '@/utils/hooks/use-wallet'; const queryString = require('query-string'); -type FundWalletEntities = { link: LinkProps['to']; icon: ReactNode }; +type FundWalletEntities = { pathname: string; search?: string; icon: ReactNode }; type UseEntitiesResult = { exchanges: FundWalletEntities[]; @@ -29,43 +28,48 @@ const useEntities = (): UseEntitiesResult => { const wallet = useWallet(); const banxaLink = { - pathname: BANXA_LINK, + pathname: EXTERNAL_PAGES.BANXA, search: queryString.stringify({ - [LINK_QUERY_PARAMETERS.BANXA.WALLET_ADDRESS]: wallet.getRelayChainAddress(), - [LINK_QUERY_PARAMETERS.BANXA.FIAT_TYPE]: 'EUR', - [LINK_QUERY_PARAMETERS.BANXA.COIN_TYPE]: GOVERNANCE_TOKEN.ticker + [EXTERNAL_QUERY_PARAMETERS.BANXA.WALLET_ADDRESS]: wallet.getRelayChainAddress(), + [EXTERNAL_QUERY_PARAMETERS.BANXA.FIAT_TYPE]: 'EUR', + [EXTERNAL_QUERY_PARAMETERS.BANXA.COIN_TYPE]: GOVERNANCE_TOKEN.ticker }) }; if (process.env.REACT_APP_RELAY_CHAIN_NAME === POLKADOT) { const exchanges = [ { - link: 'https://acala.network/', + pathname: 'https://acala.network/', icon: }, { - link: 'https://stellaswap.com/', + pathname: 'https://stellaswap.com/', icon: }, { - link: 'https://trade.kraken.com/charts/KRAKEN:INTR-USD', + pathname: 'https://trade.kraken.com/charts/KRAKEN:INTR-USD', icon: }, { - link: 'https://www.gate.io/trade/INTR_USDT', + pathname: 'https://www.gate.io/trade/INTR_USDT', icon: }, { - link: 'https://www.mexc.com/exchange/INTR_USDT', + pathname: 'https://www.mexc.com/exchange/INTR_USDT', icon: }, { - link: 'https://www.lbank.info/exchange/intr/usdt', + pathname: 'https://www.lbank.info/exchange/intr/usdt', icon: } ]; - const payments = [{ link: banxaLink, icon: banxa }]; + const payments = [ + { + ...banxaLink, + icon: banxa + } + ]; return { exchanges, @@ -74,24 +78,24 @@ const useEntities = (): UseEntitiesResult => { } else if (process.env.REACT_APP_RELAY_CHAIN_NAME === KUSAMA) { const exchanges = [ { - link: 'https://www.kraken.com/en-gb/prices/kint-kintsugi-price-chart/usd-us-dollar?interval=1m', + pathname: 'https://www.kraken.com/en-gb/prices/kint-kintsugi-price-chart/usd-us-dollar?interval=1m', icon: }, { - link: 'https://www.gate.io/de/trade/kint_usdt', + pathname: 'https://www.gate.io/de/trade/kint_usdt', icon: }, { - link: 'https://dex.zenlink.pro/#/swap', + pathname: 'https://dex.zenlink.pro/#/swap', icon: }, { - link: 'https://www.mexc.com/de-DE/exchange/KINT_USDT', + pathname: 'https://www.mexc.com/de-DE/exchange/KINT_USDT', icon: } ]; - const payments = [{ link: banxaLink, icon: banxa }]; + const payments = [{ ...banxaLink, icon: banxa }]; return { exchanges, diff --git a/src/config/links.ts b/src/config/links.ts index 7e5ed0781d..8f1d7557b1 100644 --- a/src/config/links.ts +++ b/src/config/links.ts @@ -19,14 +19,6 @@ const KINTSUGI_SUBSCAN_LINK = 'https://kintsugi.subscan.io'; const INTERLAY_VAULT_DOCS_LINK = 'https://docs.interlay.io/#/vault/overview'; const INTERLAY_DOS_AND_DONTS_DOCS_LINK = 'https://docs.interlay.io/#/vault/installation?id=dos-and-donts'; -const LINK_QUERY_PARAMETERS = { - BANXA: { - WALLET_ADDRESS: 'walletAddress', - FIAT_TYPE: 'fiatType', - COIN_TYPE: 'coinType' - } -}; - const BANXA_LINK = 'http://talisman.banxa.com/'; export { @@ -48,6 +40,5 @@ export { KINTSUGI_GOVERNANCE_LINK, KINTSUGI_SUBSCAN_LINK, KINTSUGI_TERMS_AND_CONDITIONS_LINK, - KINTSUGI_USE_WRAPPED_CURRENCY_LINK, - LINK_QUERY_PARAMETERS + KINTSUGI_USE_WRAPPED_CURRENCY_LINK }; diff --git a/src/utils/constants/links.ts b/src/utils/constants/links.ts index 852612b127..7c64f49388 100644 --- a/src/utils/constants/links.ts +++ b/src/utils/constants/links.ts @@ -1,3 +1,5 @@ +import { BANXA_LINK } from '@/config/links'; + const URL_PARAMETERS = Object.freeze({ VAULT: { ACCOUNT: 'vaultAccount', @@ -32,6 +34,10 @@ const PAGES = Object.freeze({ WALLET: '/wallet' }); +const EXTERNAL_PAGES = Object.freeze({ + BANXA: `${BANXA_LINK}` +}); + const QUERY_PARAMETERS = Object.freeze({ TAB: 'tab', PAGE: 'page', @@ -45,4 +51,12 @@ const QUERY_PARAMETERS = Object.freeze({ } }); -export { PAGES, QUERY_PARAMETERS, URL_PARAMETERS }; +const EXTERNAL_QUERY_PARAMETERS = Object.freeze({ + BANXA: { + WALLET_ADDRESS: 'walletAddress', + FIAT_TYPE: 'fiatType', + COIN_TYPE: 'coinType' + } +}); + +export { EXTERNAL_PAGES, EXTERNAL_QUERY_PARAMETERS, PAGES, QUERY_PARAMETERS, URL_PARAMETERS }; From 8e61009e8dd885976283ac73d4d454023ff1cd5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rui=20Sim=C3=A3o?= Date: Tue, 16 May 2023 09:49:53 +0100 Subject: [PATCH 10/12] fix: replace T&C hidden CTA to AuthCTA --- .../PoolsInsights/PoolsInsights.tsx | 16 ++++---- .../LoansInsights/LoansInsights.tsx | 14 +++---- .../components/Rewards/Rewards.styles.tsx | 5 ++- .../Vault/components/Rewards/Rewards.tsx | 37 +++++++++---------- 4 files changed, 33 insertions(+), 39 deletions(-) diff --git a/src/pages/AMM/Pools/components/PoolsInsights/PoolsInsights.tsx b/src/pages/AMM/Pools/components/PoolsInsights/PoolsInsights.tsx index 09f41e7566..a845df1639 100644 --- a/src/pages/AMM/Pools/components/PoolsInsights/PoolsInsights.tsx +++ b/src/pages/AMM/Pools/components/PoolsInsights/PoolsInsights.tsx @@ -5,8 +5,8 @@ import { useMutation } from 'react-query'; import { toast } from 'react-toastify'; import { formatUSD } from '@/common/utils/utils'; -import { Card, CTA, Dl, DlGroup } from '@/component-library'; -import { IsAuthenticated } from '@/components'; +import { Card, Dl, DlGroup } from '@/component-library'; +import { AuthCTA } from '@/components'; import { calculateAccountLiquidityUSD, calculateTotalLiquidityUSD } from '@/pages/AMM/shared/utils'; import { submitExtrinsic } from '@/utils/helpers/extrinsic'; import { AccountPoolsData } from '@/utils/hooks/api/amm/use-get-account-pools'; @@ -87,13 +87,11 @@ const PoolsInsights = ({ pools, accountPoolsData, refetch }: PoolsInsightsProps) {t('rewards')} {formatUSD(totalClaimableRewardUSD, { compact: true })} - - {hasClaimableRewards && ( - - Claim - - )} - + {hasClaimableRewards && ( + + Claim + + )} ); diff --git a/src/pages/Loans/LoansOverview/components/LoansInsights/LoansInsights.tsx b/src/pages/Loans/LoansOverview/components/LoansInsights/LoansInsights.tsx index 1d62c7c1a5..ff56e4f6a0 100644 --- a/src/pages/Loans/LoansOverview/components/LoansInsights/LoansInsights.tsx +++ b/src/pages/Loans/LoansOverview/components/LoansInsights/LoansInsights.tsx @@ -5,7 +5,7 @@ import { toast } from 'react-toastify'; import { formatNumber, formatPercentage, formatUSD } from '@/common/utils/utils'; import { Card, CTA, Dl, DlGroup } from '@/component-library'; -import { IsAuthenticated } from '@/components'; +import { AuthCTA } from '@/components'; import ErrorModal from '@/legacy-components/ErrorModal'; import { submitExtrinsic } from '@/utils/helpers/extrinsic'; import { AccountLendingStatistics } from '@/utils/hooks/api/loans/use-get-account-lending-statistics'; @@ -75,13 +75,11 @@ const LoansInsights = ({ statistics }: LoansInsightsProps): JSX.Element => { Rewards {subsidyRewardsAmountLabel} - - {hasSubsidyRewards && ( - - Claim - - )} - + {hasSubsidyRewards && ( + + Claim + + )} {claimRewardsMutation.isError && ( diff --git a/src/pages/Vaults/Vault/components/Rewards/Rewards.styles.tsx b/src/pages/Vaults/Vault/components/Rewards/Rewards.styles.tsx index 2578dd98a8..78b2a83472 100644 --- a/src/pages/Vaults/Vault/components/Rewards/Rewards.styles.tsx +++ b/src/pages/Vaults/Vault/components/Rewards/Rewards.styles.tsx @@ -1,6 +1,7 @@ import styled from 'styled-components'; -import { CTA, H2, theme } from '@/component-library'; +import { H2, theme } from '@/component-library'; +import { AuthCTA } from '@/components'; const StyledRewardsTitleWrapper = styled.div` display: flex; @@ -19,7 +20,7 @@ type StyledCTAProps = { $loading: boolean; }; -const StyledCTA = styled(CTA)` +const StyledCTA = styled(AuthCTA)` position: relative; padding-left: ${(props) => props.$loading && theme.spacing.spacing8}; `; diff --git a/src/pages/Vaults/Vault/components/Rewards/Rewards.tsx b/src/pages/Vaults/Vault/components/Rewards/Rewards.tsx index 2b7be815f1..e2bc840f77 100644 --- a/src/pages/Vaults/Vault/components/Rewards/Rewards.tsx +++ b/src/pages/Vaults/Vault/components/Rewards/Rewards.tsx @@ -7,7 +7,6 @@ import { toast } from 'react-toastify'; import { formatNumber, formatUSD } from '@/common/utils/utils'; import { CardProps } from '@/component-library'; import { LoadingSpinner } from '@/component-library/LoadingSpinner'; -import { IsAuthenticated } from '@/components'; import { GOVERNANCE_TOKEN_SYMBOL, WRAPPED_TOKEN } from '@/config/relay-chains'; import ErrorModal from '@/legacy-components/ErrorModal'; import { ZERO_GOVERNANCE_TOKEN_AMOUNT } from '@/utils/constants/currency'; @@ -83,25 +82,23 @@ const Rewards = ({ const stakingTitle = ( Rewards - - {hasWithdrawRewardsBtn && ( - - {/* TODO: temporary approach. Loading spinner should be added to the CTA itself */} - {claimRewardsMutation.isLoading && ( - - - - )} - Withdraw all rewards - - )} - + {hasWithdrawRewardsBtn && ( + + {/* TODO: temporary approach. Loading spinner should be added to the CTA itself */} + {claimRewardsMutation.isLoading && ( + + + + )} + Withdraw all rewards + + )} {claimRewardsMutation.isError && ( Date: Tue, 16 May 2023 15:31:38 +0100 Subject: [PATCH 11/12] fix: code review --- src/components/FundWallet/use-entities.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/FundWallet/use-entities.tsx b/src/components/FundWallet/use-entities.tsx index e189dba8c6..afb4868502 100644 --- a/src/components/FundWallet/use-entities.tsx +++ b/src/components/FundWallet/use-entities.tsx @@ -30,7 +30,7 @@ const useEntities = (): UseEntitiesResult => { const banxaLink = { pathname: EXTERNAL_PAGES.BANXA, search: queryString.stringify({ - [EXTERNAL_QUERY_PARAMETERS.BANXA.WALLET_ADDRESS]: wallet.getRelayChainAddress(), + [EXTERNAL_QUERY_PARAMETERS.BANXA.WALLET_ADDRESS]: wallet.account?.toString(), [EXTERNAL_QUERY_PARAMETERS.BANXA.FIAT_TYPE]: 'EUR', [EXTERNAL_QUERY_PARAMETERS.BANXA.COIN_TYPE]: GOVERNANCE_TOKEN.ticker }) From a383fb9867ee06dd54d8252d92ad672baaf3050e Mon Sep 17 00:00:00 2001 From: Thomas Jeatt Date: Wed, 17 May 2023 10:56:19 +0100 Subject: [PATCH 12/12] chore: fix linting error --- .../LoansOverview/components/LoansInsights/LoansInsights.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/Loans/LoansOverview/components/LoansInsights/LoansInsights.tsx b/src/pages/Loans/LoansOverview/components/LoansInsights/LoansInsights.tsx index ff56e4f6a0..41bfd6a148 100644 --- a/src/pages/Loans/LoansOverview/components/LoansInsights/LoansInsights.tsx +++ b/src/pages/Loans/LoansOverview/components/LoansInsights/LoansInsights.tsx @@ -4,7 +4,7 @@ import { useMutation } from 'react-query'; import { toast } from 'react-toastify'; import { formatNumber, formatPercentage, formatUSD } from '@/common/utils/utils'; -import { Card, CTA, Dl, DlGroup } from '@/component-library'; +import { Card, Dl, DlGroup } from '@/component-library'; import { AuthCTA } from '@/components'; import ErrorModal from '@/legacy-components/ErrorModal'; import { submitExtrinsic } from '@/utils/helpers/extrinsic';