From a9878a1baa3d8fb26a60c4b120eb9bec088f0ac6 Mon Sep 17 00:00:00 2001 From: Georges KABBOUCHI Date: Sun, 8 Aug 2021 13:07:21 +0300 Subject: [PATCH] payback fixes --- .../compound/SidebarCompoundPayback.vue | 20 +++++++++++-------- composables/useCompoundPosition.ts | 3 --- composables/useSidebar.ts | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/components/sidebar/context/compound/SidebarCompoundPayback.vue b/components/sidebar/context/compound/SidebarCompoundPayback.vue index 8c1780f..ac9b487 100644 --- a/components/sidebar/context/compound/SidebarCompoundPayback.vue +++ b/components/sidebar/context/compound/SidebarCompoundPayback.vue @@ -113,7 +113,7 @@ export default defineComponent({ const { getTokenByKey, valInt } = useToken() const { getBalanceByKey, getBalanceRawByKey, fetchBalances } = useBalances() const { formatNumber, formatUsdMax, formatUsd } = useFormatting() - const { isZero, gt, plus, max, minus } = useBigNumber() + const { isZero, gte, plus, max, minus, min } = useBigNumber() const { parseSafeFloat } = useParsing() const { showPendingTransaction } = useNotification() const tokenId = computed(() => props.tokenId) @@ -122,7 +122,7 @@ export default defineComponent({ const rootTokenKey = computed(() => ctokens[networkName.value].rootTokens.includes(tokenKey.value) ? tokenKey.value : 'eth') - const { status, displayPositions, liquidation, liquidationPrice, liquidationMaxPrice } = useCompoundPosition({ + const { status, position, displayPositions, liquidation, liquidationPrice, liquidationMaxPrice } = useCompoundPosition({ overridePosition: (position) => { if (tokenId.value !== position.cTokenId) return position @@ -137,7 +137,7 @@ export default defineComponent({ const amountParsed = computed(() => parseSafeFloat(amount.value)) const currentPosition = computed(() => - displayPositions.value.find((position) => position.cTokenId === tokenId.value) + position.value.data.find((position) => position.cTokenId === tokenId.value) ) const token = computed(() => getTokenByKey(rootTokenKey.value)) @@ -152,14 +152,17 @@ export default defineComponent({ const address = computed(() => token.value?.address) - const { toggle, isMaxAmount } = useMaxAmountActive(amount, balance) - const { validateAmount, validateLiquidation, validateLiquidity, validateIsLoggedIn } = useValidators() + const maxBalance = computed(() => min(balance.value, tokenMaxBalance.value).toFixed()) + const { toggle, isMaxAmount } = useMaxAmountActive(amount, maxBalance) + + const { validateAmount, validateLiquidation, validateIsLoggedIn } = useValidators() const errors = computed(() => { const hasAmountValue = !isZero(amount.value) return { - amount: { message: validateAmount(amountParsed.value), show: hasAmountValue }, + + amount: { message: validateAmount(amountParsed.value, maxBalance.value), show: hasAmountValue }, liquidation: { message: validateLiquidation(status.value, liquidation.value), show: hasAmountValue }, auth: { message: validateIsLoggedIn(!!account.value), show: true }, } @@ -179,8 +182,6 @@ export default defineComponent({ const spells = dsa.value.Spell() - const rateMode = rateType.value?.rateMode - spells.add({ connector: 'compound', method: 'payback', @@ -213,7 +214,10 @@ export default defineComponent({ formatUsdMax, formatUsd, toggle, + displayPositions, + currentPosition, isMaxAmount, + liquidation, liquidationPrice, liquidationMaxPrice, errorMessages, diff --git a/composables/useCompoundPosition.ts b/composables/useCompoundPosition.ts index 1fb3366..7fa6eb5 100644 --- a/composables/useCompoundPosition.ts +++ b/composables/useCompoundPosition.ts @@ -126,9 +126,6 @@ export function useCompoundPosition( stats.ethSupplied = supply; } - console.log(key, supply, borrow, priceInEth, factor); - - stats.totalSupplyInEth = plus( stats.totalSupplyInEth, times(supply, priceInEth) diff --git a/composables/useSidebar.ts b/composables/useSidebar.ts index 55fa797..2f10f85 100644 --- a/composables/useSidebar.ts +++ b/composables/useSidebar.ts @@ -21,7 +21,7 @@ import SidebarWithdraw from '~/components/sidebar/context/SidebarWithdraw.vue' import SidebarCompoundWithdraw from '~/components/sidebar/context/compound/SidebarCompoundWithdraw.vue' import SidebarCompoundSupply from '~/components/sidebar/context/compound/SidebarCompoundSupply.vue' import SidebarCompoundBorrow from '~/components/sidebar/context/compound/SidebarCompoundBorrow.vue' -import SidebarCompoundPayback from '~/components/sidebar/context/compound/SidebarCompoundBorrow.vue' +import SidebarCompoundPayback from '~/components/sidebar/context/compound/SidebarCompoundPayback.vue' const sidebars = {