From d99daf9facf669ae3d2b1bd32e517d40b4ba4f65 Mon Sep 17 00:00:00 2001 From: Georges KABBOUCHI Date: Tue, 27 Jul 2021 22:16:38 +0300 Subject: [PATCH] withdraw --- .../context/aaveV2/SidebarAaveV2Supply.vue | 10 +- .../context/aaveV2/SidebarAaveV2Withdraw.vue | 215 ++++++++++++++++++ composables/useAaveV2Position.ts | 1 + composables/useSidebar.ts | 6 +- composables/useValidators.ts | 16 +- 5 files changed, 242 insertions(+), 6 deletions(-) create mode 100644 components/sidebar/context/aaveV2/SidebarAaveV2Withdraw.vue diff --git a/components/sidebar/context/aaveV2/SidebarAaveV2Supply.vue b/components/sidebar/context/aaveV2/SidebarAaveV2Supply.vue index c70c74d..3bd4d71 100644 --- a/components/sidebar/context/aaveV2/SidebarAaveV2Supply.vue +++ b/components/sidebar/context/aaveV2/SidebarAaveV2Supply.vue @@ -44,7 +44,7 @@ @@ -84,6 +84,7 @@ import { useDSA } from '~/composables/useDSA' import ButtonCTA from '~/components/common/input/ButtonCTA.vue' import { useNotification } from '~/composables/useNotification' import Button from '~/components/Button.vue' +import { useSidebar } from '~/composables/useSidebar' export default defineComponent({ components: { InputNumeric, ToggleButton, ButtonCTA, Button }, @@ -91,10 +92,11 @@ export default defineComponent({ tokenKey: { type: String, required: true }, }, setup(props) { + const { close} = useSidebar() const { networkName, account } = useWeb3() const { dsa } = useDSA() const { getTokenByKey, valInt } = useToken() - const { getBalanceByKey } = useBalances() + const { getBalanceByKey, fetchBalances } = useBalances() const { formatNumber, formatUsdMax, formatUsd } = useFormatting() const { isZero, gt, plus } = useBigNumber() const { parseSafeFloat } = useParsing() @@ -162,7 +164,11 @@ export default defineComponent({ from: account.value, }) + fetchBalances(true) + pending.value = false + + close() } return { diff --git a/components/sidebar/context/aaveV2/SidebarAaveV2Withdraw.vue b/components/sidebar/context/aaveV2/SidebarAaveV2Withdraw.vue new file mode 100644 index 0000000..75ebcaa --- /dev/null +++ b/components/sidebar/context/aaveV2/SidebarAaveV2Withdraw.vue @@ -0,0 +1,215 @@ + + + diff --git a/composables/useAaveV2Position.ts b/composables/useAaveV2Position.ts index 2e3e4ff..6d1152c 100644 --- a/composables/useAaveV2Position.ts +++ b/composables/useAaveV2Position.ts @@ -306,6 +306,7 @@ export function useAaveV2Position( }); return { + stats, displayPositions, position, fetchPosition, diff --git a/composables/useSidebar.ts b/composables/useSidebar.ts index d2964a7..1d57d13 100644 --- a/composables/useSidebar.ts +++ b/composables/useSidebar.ts @@ -7,12 +7,12 @@ import { watch } from "@nuxtjs/composition-api"; -import SidebarAaveV2Supply from "~/components/sidebar/context/aaveV2/SidebarAaveV2Supply.vue"; import { useDSA } from "./useDSA"; import { useWeb3 } from "./useWeb3"; +import SidebarAaveV2Supply from "~/components/sidebar/context/aaveV2/SidebarAaveV2Supply.vue"; +import SidebarAaveV2Withdraw from '~/components/sidebar/context/aaveV2/SidebarAaveV2Withdraw.vue' // import SidebarAaveV2Borrow from '~/components/sidebar/context/aaveV2/SidebarAaveV2Borrow.vue' // import SidebarAaveV2Payback from '~/components/sidebar/context/aaveV2/SidebarAaveV2Payback.vue' -// import SidebarAaveV2Withdraw from '~/components/sidebar/context/aaveV2/SidebarAaveV2Withdraw.vue' const sidebars = { "/polygon/aave-v2": { component: null }, @@ -20,7 +20,7 @@ const sidebars = { "/polygon/aave-v2#supply": { component: SidebarAaveV2Supply }, "/polygon/aave-v2#borrow": { component: null }, "/polygon/aave-v2#payback": { component: null }, - "/polygon/aave-v2#withdraw": { component: null }, + "/polygon/aave-v2#withdraw": { component: SidebarAaveV2Withdraw }, "/polygon/aave-v2#withdraw-token": { component: null, back: { hash: "withdraw-overview" } diff --git a/composables/useValidators.ts b/composables/useValidators.ts index b2ab482..4255bc1 100644 --- a/composables/useValidators.ts +++ b/composables/useValidators.ts @@ -1,6 +1,8 @@ import { useBigNumber } from "./useBigNumber"; +import { useFormatting } from "./useFormatting"; export function useValidators() { + const { formatNumber } = useFormatting() const { isZero, minus, eq, gt } = useBigNumber(); function validateAmount(amountParsed, balance = null, options = null) { @@ -37,9 +39,21 @@ export function useValidators() { return null; } + function validateLiquidity(borrow, availableLiquidity, tokenSymbol, withdraw = false) { + if (gt(borrow, availableLiquidity)) { + let action = 'borrow' + if (withdraw) { + action = 'withdraw' + } + return `Not enough liquidity to ${action} ${formatNumber(borrow, 2)} ${tokenSymbol}` + } + return null + } + return { validateAmount, validateLiquidation, - validateIsLoggedIn + validateIsLoggedIn, + validateLiquidity }; }