diff --git a/nym-wallet/src/components/Bonding/BondedMixnode.tsx b/nym-wallet/src/components/Bonding/BondedMixnode.tsx index 5d63555ddb..1859cf0320 100644 --- a/nym-wallet/src/components/Bonding/BondedMixnode.tsx +++ b/nym-wallet/src/components/Bonding/BondedMixnode.tsx @@ -114,7 +114,6 @@ export const BondedMixnode = ({ ), id: 'actions-cell', diff --git a/nym-wallet/src/components/Bonding/BondedMixnodeActions.tsx b/nym-wallet/src/components/Bonding/BondedMixnodeActions.tsx index 37b52452c7..065e75ca5d 100644 --- a/nym-wallet/src/components/Bonding/BondedMixnodeActions.tsx +++ b/nym-wallet/src/components/Bonding/BondedMixnodeActions.tsx @@ -20,6 +20,7 @@ export const BondedMixnodeActions = ({ const handleClose = () => setIsOpen(false); const handleActionClick = (action: TBondedMixnodeActions) => { + console.log({ action }); onActionSelect(action); handleClose(); }; diff --git a/nym-wallet/src/components/Bonding/modals/BondMoreModal.tsx b/nym-wallet/src/components/Bonding/modals/BondMoreModal.tsx index 88518abc28..64f5eb9e65 100644 --- a/nym-wallet/src/components/Bonding/modals/BondMoreModal.tsx +++ b/nym-wallet/src/components/Bonding/modals/BondMoreModal.tsx @@ -8,6 +8,7 @@ import { TokenPoolSelector, TPoolOption } from 'src/components/TokenPoolSelector import { ConfirmTx } from 'src/components/ConfirmTX'; import { useGetFee } from 'src/hooks/useGetFee'; import { validateAmount, validateKey } from 'src/utils'; +import { TBondedMixnode } from 'src/context'; export const BondMoreModal = ({ currentBond, @@ -17,14 +18,15 @@ export const BondMoreModal = ({ onClose, }: { currentBond: DecCoin; + mixId: string; userBalance?: string; hasVestingTokens: boolean; - onConfirm: (args: { additionalBond: DecCoin; signature: string; tokenPool: TPoolOption }) => Promise; + onConfirm: (args: { additionalBond: DecCoin; tokenPool: TPoolOption }) => Promise; onClose: () => void; }) => { const { fee, resetFeeState } = useGetFee(); const [additionalBond, setAdditionalBond] = useState({ amount: '0', denom: currentBond.denom }); - const [signature, setSignature] = useState(''); + // const [signature, setSignature] = useState(''); const [tokenPool, setTokenPool] = useState('balance'); const [errorAmount, setErrorAmount] = useState(false); const [errorSignature, setErrorSignature] = useState(false); @@ -35,9 +37,9 @@ export const BondMoreModal = ({ signature: false, }; - if (!validateKey(signature || '', 64)) { - errors.signature = true; - } + // if (!validateKey(signature || '', 64)) { + // errors.signature = true; + // } if (!additionalBond?.amount) { errors.amount = true; @@ -47,8 +49,8 @@ export const BondMoreModal = ({ errors.amount = true; } - if (!errors.amount && !errors.signature) { - onConfirm({ additionalBond, signature, tokenPool }); + if (!errors.amount) { + onConfirm({ additionalBond, tokenPool }); } else { setErrorAmount(errors.amount); setErrorSignature(errors.signature); @@ -65,7 +67,7 @@ export const BondMoreModal = ({ header="Bond more details" open fee={fee} - onConfirm={async () => onConfirm({ additionalBond, signature, tokenPool })} + onConfirm={async () => onConfirm({ additionalBond, tokenPool })} onPrev={resetFeeState} > @@ -98,7 +100,7 @@ export const BondMoreModal = ({ validationError={errorAmount ? 'Please enter a valid amount' : undefined} /> - + {/* {errorSignature && Invalid signature} - + */} diff --git a/nym-wallet/src/context/bonding.tsx b/nym-wallet/src/context/bonding.tsx index 524a9ea0be..d980e4688e 100644 --- a/nym-wallet/src/context/bonding.tsx +++ b/nym-wallet/src/context/bonding.tsx @@ -100,7 +100,7 @@ export type TBondingContext = { bondMixnode: (data: TBondMixNodeArgs, tokenPool: TokenPool) => Promise; bondGateway: (data: TBondGatewayArgs, tokenPool: TokenPool) => Promise; unbond: (fee?: FeeDetails) => Promise; - bondMore: (signature: string, amount: DecCoin, fee?: FeeDetails) => Promise; + bondMore: (amount: DecCoin, mixId: string) => Promise; redeemRewards: (fee?: FeeDetails) => Promise; updateMixnode: (pm: string, fee?: FeeDetails) => Promise; checkOwnership: () => Promise; @@ -431,9 +431,49 @@ export const BondingContextProvider = ({ children }: { children?: React.ReactNod return tx; }; - const bondMore = async (_signature: string, _additionalBond: DecCoin) => - // TODO to implement - undefined; + const bondGatewayaa = async (data: TBondGatewayArgs, tokenPool: TokenPool) => { + let tx: TransactionExecuteResult | undefined; + setIsLoading(true); + try { + if (tokenPool === 'balance') { + tx = await bondGatewayRequest(data); + await userBalance.fetchBalance(); + } + if (tokenPool === 'locked') { + tx = await vestingBondGateway(data); + await userBalance.fetchTokenAllocation(); + } + return tx; + } catch (e: any) { + Console.warn(e); + setError(`an error occurred: ${e}`); + } finally { + setIsLoading(false); + } + return undefined; + }; + + const bondMore = async (amount: DecCoin, mixId: string) => { + let tx: TransactionExecuteResult | undefined; + setIsLoading(true); + try { + if (tokenPool === 'balance') { + tx = await bondGatewayRequest(data); + await userBalance.fetchBalance(); + } + if (tokenPool === 'locked') { + tx = await vestingBondGateway(data); + await userBalance.fetchTokenAllocation(); + } + return tx; + } catch (e: any) { + Console.warn(e); + setError(`an error occurred: ${e}`); + } finally { + setIsLoading(false); + } + return undefined; + }; const memoizedValue = useMemo( () => ({ diff --git a/nym-wallet/src/pages/bonding/Bonding.tsx b/nym-wallet/src/pages/bonding/Bonding.tsx index d1ec197b0f..79d8808c3f 100644 --- a/nym-wallet/src/pages/bonding/Bonding.tsx +++ b/nym-wallet/src/pages/bonding/Bonding.tsx @@ -1,6 +1,6 @@ import React, { useContext, useState } from 'react'; import { useNavigate } from 'react-router-dom'; -import { FeeDetails } from '@nymproject/types'; +import { FeeDetails, DecCoin } from '@nymproject/types'; import { Box } from '@mui/material'; import { TPoolOption } from 'src/components'; import { Bond } from 'src/components/Bonding/Bond'; @@ -8,6 +8,7 @@ import { BondedMixnode } from 'src/components/Bonding/BondedMixnode'; import { TBondedMixnodeActions } from 'src/components/Bonding/BondedMixnodeActions'; import { BondGatewayModal } from 'src/components/Bonding/modals/BondGatewayModal'; import { BondMixnodeModal } from 'src/components/Bonding/modals/BondMixnodeModal'; +import { BondMoreModal } from 'src/components/Bonding/modals/BondMoreModal'; import { ConfirmationDetailProps, ConfirmationDetailsModal } from 'src/components/Bonding/modals/ConfirmationModal'; import { ErrorModal } from 'src/components/Modals/ErrorModal'; import { LoadingModal } from 'src/components/Modals/LoadingModal'; @@ -29,7 +30,8 @@ const Bonding = () => { const navigate = useNavigate(); - const { bondedNode, bondMixnode, bondGateway, redeemRewards, isLoading, checkOwnership } = useBondingContext(); + const { bondedNode, bondMixnode, bondGateway, redeemRewards, isLoading, checkOwnership, bondMore } = + useBondingContext(); const handleCloseModal = async () => { setShowModal(undefined); @@ -66,6 +68,17 @@ const Bonding = () => { }); }; + const handleBondMore = async (args: { additionalBond: DecCoin; tokenPool: TPoolOption }) => { + const { additionalBond } = args; + setShowModal(undefined); + const tx = await bondMore(additionalBond, bondedNode.mixId); + setConfirmationDetails({ + status: 'success', + title: 'Bond More successful', + txUrl: `${urls(network).blockExplorer}/transaction/${tx?.transaction_hash}`, + }); + }; + const handleRedeemReward = async (fee?: FeeDetails) => { setShowModal(undefined); const tx = await redeemRewards(fee); @@ -77,6 +90,7 @@ const Bonding = () => { }; const handleBondedMixnodeAction = (action: TBondedMixnodeActions) => { + console.log({ action }); switch (action) { case 'bondMore': { setShowModal('bond-more'); @@ -112,6 +126,7 @@ const Bonding = () => { {bondedNode && isGateway(bondedNode) && ( )} + {showModal === 'bond-mixnode' && ( { /> )} + {showModal === 'bond-more' && bondedNode && isMixnode(bondedNode) && ( + setShowModal(undefined)} + /> + )} + {showModal === 'redeem' && bondedNode && isMixnode(bondedNode) && ( @@ -32,3 +32,6 @@ export const unbond = async (type: EnumNodeType) => { if (type === EnumNodeType.mixnode) return unbondMixNode(); return unbondGateway(); }; + +export const bondMore = async (args: TBondMoreArgs) => + invokeWrapper('bond_gateway', args); diff --git a/nym-wallet/src/types/global.ts b/nym-wallet/src/types/global.ts index d5bb61c26d..d0302b9218 100644 --- a/nym-wallet/src/types/global.ts +++ b/nym-wallet/src/types/global.ts @@ -49,6 +49,11 @@ export type TBondMixNodeArgs = { fee?: Fee; }; +export type TBondMoreArgs = { + mixId: MixNode; + amount: string; +}; + export type TNodeDescription = { name: string; description: string;