From 1dc3274a0a48ec342c2f614764ed60f1aafc68f6 Mon Sep 17 00:00:00 2001 From: bartosz-lipinski <264380+bartosz-lipinski@users.noreply.github.com> Date: Thu, 26 Nov 2020 20:31:10 -0600 Subject: [PATCH] feat: add repay, withdraw confirmation --- src/components/BorrowInput/index.tsx | 1 + src/components/DepositInput/index.tsx | 1 + src/components/RepayInput/index.tsx | 34 +++++++++++++++--- src/components/WithdrawInput/index.tsx | 49 ++++++++++++++++++-------- 4 files changed, 66 insertions(+), 19 deletions(-) diff --git a/src/components/BorrowInput/index.tsx b/src/components/BorrowInput/index.tsx index cd47dd8..95ba0ce 100644 --- a/src/components/BorrowInput/index.tsx +++ b/src/components/BorrowInput/index.tsx @@ -87,6 +87,7 @@ export const BorrowInput = (props: { : undefined ); + setValue(""); setShowConfirmation(true); } catch { // TODO: diff --git a/src/components/DepositInput/index.tsx b/src/components/DepositInput/index.tsx index 4ed4cf2..4d98f9e 100644 --- a/src/components/DepositInput/index.tsx +++ b/src/components/DepositInput/index.tsx @@ -46,6 +46,7 @@ export const DepositInput = (props: { wallet ); + setValue(""); setShowConfirmation(true); } catch { // TODO: diff --git a/src/components/RepayInput/index.tsx b/src/components/RepayInput/index.tsx index 0bf3c81..41a04ca 100644 --- a/src/components/RepayInput/index.tsx +++ b/src/components/RepayInput/index.tsx @@ -6,7 +6,7 @@ import { LendingReserveParser, } from "../../models"; import { TokenIcon } from "../TokenIcon"; -import { Button, Card, Slider } from "antd"; +import { Button, Card, Slider, Spin } from "antd"; import { cache, ParsedAccount, useMint } from "../../contexts/accounts"; import { NumericInput } from "../Input/numeric"; import { useConnection } from "../../contexts/connection"; @@ -21,6 +21,11 @@ import { toLamports, } from "../../utils/utils"; import { LABELS } from "../../constants"; +import { LoadingOutlined } from "@ant-design/icons"; +import { ActionConfirmation} from './../ActionConfirmation'; +import { BackButton } from "./../BackButton"; + +const antIcon = ; export const RepayInput = (props: { className?: string; @@ -30,6 +35,8 @@ export const RepayInput = (props: { const connection = useConnection(); const { wallet } = useWallet(); const [value, setValue] = useState(""); + const [pendingTx, setPendingTx] = useState(false); + const [showConfirmation, setShowConfirmation] = useState(false); const repayReserve = props.reserve; const obligation = props.obligation; @@ -74,7 +81,12 @@ export const RepayInput = (props: { return; } - repay( + setPendingTx(true); + + (async () => { + try { + + await repay( fromAccounts[0], lamports, obligation, @@ -84,6 +96,15 @@ export const RepayInput = (props: { connection, wallet ); + + setValue(""); + setShowConfirmation(true); + } catch { + // TODO: + }finally { + setPendingTx(false); + } +})(); }, [ lamports, connection, @@ -105,6 +126,7 @@ export const RepayInput = (props: { return ( + {showConfirmation ? setShowConfirmation(false)} /> :
{name}
- @@ -149,7 +172,7 @@ export const RepayInput = (props: { ).toFixed(2) ) } - /> + /> */}
{LABELS.SELECT_COLLATERAL}
{LABELS.REPAY_ACTION} + {pendingTx && } - + }
); }; diff --git a/src/components/WithdrawInput/index.tsx b/src/components/WithdrawInput/index.tsx index 7ceb1b5..2a57678 100644 --- a/src/components/WithdrawInput/index.tsx +++ b/src/components/WithdrawInput/index.tsx @@ -6,7 +6,7 @@ import { } from "../../hooks"; import { LendingReserve } from "../../models/lending"; import { TokenIcon } from "../TokenIcon"; -import { Button, Card } from "antd"; +import { Button, Card, Spin } from "antd"; import { NumericInput } from "../Input/numeric"; import { useConnection } from "../../contexts/connection"; import { useWallet } from "../../contexts/wallet"; @@ -14,6 +14,10 @@ import { withdraw } from "../../actions"; import { PublicKey } from "@solana/web3.js"; import "./style.less"; import { LABELS } from "../../constants"; +import { LoadingOutlined } from "@ant-design/icons"; +import { ActionConfirmation} from './../ActionConfirmation'; + +const antIcon = ; export const WithdrawInput = (props: { className?: string; @@ -23,6 +27,8 @@ export const WithdrawInput = (props: { const connection = useConnection(); const { wallet } = useWallet(); const [value, setValue] = useState(""); + const [pendingTx, setPendingTx] = useState(false); + const [showConfirmation, setShowConfirmation] = useState(false); const reserve = props.reserve; const address = props.address; @@ -37,17 +43,30 @@ export const WithdrawInput = (props: { ); const onWithdraw = useCallback(() => { - withdraw( - fromAccounts[0], - Math.ceil( - collateralBalanceLamports * - (parseFloat(value) / collateralBalanceInLiquidity) - ), - reserve, - address, - connection, - wallet - ); + setPendingTx(true); + + (async () => { + try { + await withdraw( + fromAccounts[0], + Math.ceil( + collateralBalanceLamports * + (parseFloat(value) / collateralBalanceInLiquidity) + ), + reserve, + address, + connection, + wallet + ); + + setValue(""); + setShowConfirmation(true); + } catch { + // TODO: + } finally { + setPendingTx(false); + } + })(); }, [ connection, wallet, @@ -69,6 +88,7 @@ export const WithdrawInput = (props: { return ( + {showConfirmation ? setShowConfirmation(false)} /> :
{LABELS.WITHDRAW_ACTION} + {pendingTx && } -
+ }
); };