From 8af05b6ac1602faa65a784314b57622b853ceffc Mon Sep 17 00:00:00 2001 From: Matias Poblete <86752543+MattPoblete@users.noreply.github.com> Date: Wed, 27 Nov 2024 10:03:06 -0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20defindex=20&=20vault=20fees?= =?UTF-8?q?=20on=20inspect=20modal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeployVault/ConfirmDelpoyModal.tsx | 4 +++- .../components/ManageVaults/InspectVault.tsx | 11 ++++++++++- .../components/ManageVaults/ManageVaults.tsx | 10 +++++++++- apps/dapp/src/hooks/useVault.ts | 19 ++++++++++++++++--- apps/dapp/src/store/lib/types.ts | 3 ++- 5 files changed, 40 insertions(+), 7 deletions(-) diff --git a/apps/dapp/src/components/DeployVault/ConfirmDelpoyModal.tsx b/apps/dapp/src/components/DeployVault/ConfirmDelpoyModal.tsx index 7a285b10..b136c425 100644 --- a/apps/dapp/src/components/DeployVault/ConfirmDelpoyModal.tsx +++ b/apps/dapp/src/components/DeployVault/ConfirmDelpoyModal.tsx @@ -50,7 +50,7 @@ export const ConfirmDelpoyModal = ({ isOpen, onClose }: { isOpen: boolean, onClo const feeReceiverString = useAppSelector(state => state.newVault.feeReceiver) const { transactionStatusModal: txModal, deployVaultModal: deployModal } = useContext(ModalContext); const dispatch = useAppDispatch(); - const { getIdleFunds, getInvestedFunds, getTVL, getUserBalance } = useVault() + const { getFees } = useVault() const [deployDisabled, setDeployDisabled] = useState(true); @@ -258,6 +258,7 @@ export const ConfirmDelpoyModal = ({ isOpen, onClose }: { isOpen: boolean, onClo amount: newVault.assets[index]?.amount || 0 } }) + const fees = await getFees(parsedResult) const tempVault: VaultData = { ...newVault, address: parsedResult, @@ -268,6 +269,7 @@ export const ConfirmDelpoyModal = ({ isOpen, onClose }: { isOpen: boolean, onClo totalSupply: 0, idleFunds: idleFunds, investedFunds: [{ address: '', amount: 0 }], + fees: fees, } await txModal.handleSuccess(result.txHash); dispatch(pushVault(tempVault)); diff --git a/apps/dapp/src/components/ManageVaults/InspectVault.tsx b/apps/dapp/src/components/ManageVaults/InspectVault.tsx index e3917600..e9e0a21e 100644 --- a/apps/dapp/src/components/ManageVaults/InspectVault.tsx +++ b/apps/dapp/src/components/ManageVaults/InspectVault.tsx @@ -68,7 +68,7 @@ export const InspectVault = ({ Strategies: {selectedVault.assets.map((asset: Asset, index: number) => ( - + {(strategy: Strategy, index: number) => ( @@ -109,6 +109,15 @@ export const InspectVault = ({ ))} + + Fees: + + Defindex fee: {(selectedVault.fees[0]! / 100).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits: 2 })} % + + + Vault fee: {(selectedVault.fees[1]! / 100).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits: 2 })} % + + {(address && selectedVault.userBalance) && User balance: diff --git a/apps/dapp/src/components/ManageVaults/ManageVaults.tsx b/apps/dapp/src/components/ManageVaults/ManageVaults.tsx index aee2fc75..9a903fa6 100644 --- a/apps/dapp/src/components/ManageVaults/ManageVaults.tsx +++ b/apps/dapp/src/components/ManageVaults/ManageVaults.tsx @@ -137,6 +137,8 @@ export const ManageVaults = () => { } + + {/* Interact with vault */} { + + {/* Inspect vault */} { inspectModal.setIsOpen(e.open) }} - size={'lg'} + size={'xl'} placement={'center'} > @@ -162,6 +166,8 @@ export const ManageVaults = () => { onClose={() => { inspectModal.setIsOpen(false) }} /> + + {/* Edit vault */} { editModal.setIsOpen(e.open) }} @@ -171,6 +177,8 @@ export const ManageVaults = () => { + + {/* Transaction status modal */} { txModal.setIsOpen(e.open) }} diff --git a/apps/dapp/src/hooks/useVault.ts b/apps/dapp/src/hooks/useVault.ts index 4ce916aa..3b227756 100644 --- a/apps/dapp/src/hooks/useVault.ts +++ b/apps/dapp/src/hooks/useVault.ts @@ -24,6 +24,7 @@ export enum VaultMethod { GETIDLEFUNDS = "fetch_current_idle_funds", GETINVESTEDFUNDS = "fetch_current_invested_funds", SETFEERECIEVER = "set_fee_receiver", + GETFEES = "get_fees", } const isObject = (val: unknown) => typeof val === 'object' && val !== null && !Array.isArray(val); @@ -67,7 +68,8 @@ export const useVault = (vaultAddress?: string | undefined) => { TVL, totalSupply, idleFunds, - investedFunds + investedFunds, + fees ] = await Promise.all([ getVaultManager(vaultAddress), getVaultEmergencyManager(vaultAddress), @@ -77,7 +79,8 @@ export const useVault = (vaultAddress?: string | undefined) => { getTVL(vaultAddress), getVaultTotalSupply(vaultAddress), getIdleFunds(vaultAddress), - getInvestedFunds(vaultAddress) + getInvestedFunds(vaultAddress), + getFees(vaultAddress) ]); for (let asset of assets){ const symbol = await getTokenSymbol(asset.address, sorobanContext); @@ -96,6 +99,7 @@ export const useVault = (vaultAddress?: string | undefined) => { totalSupply: totalSupply || 0, idleFunds: idleFunds || [], investedFunds: investedFunds || [], + fees: fees || [50,0], } return newData } catch (error) { @@ -201,6 +205,14 @@ export const useVault = (vaultAddress?: string | undefined) => { console.error(error); } } + const getFees = async (vaultAddress: string) => { + try { + const fees = await vault(VaultMethod.GETFEES, vaultAddress, undefined, false).then((res: any) => scValToNative(res)); + return fees || [50,0]; + } catch (error) { + console.error(error); + } + } const vaultInfo = getVaultInfo(vaultAddress!); return { @@ -215,6 +227,7 @@ export const useVault = (vaultAddress?: string | undefined) => { getUserBalance, getTVL, getIdleFunds, - getInvestedFunds, + getInvestedFunds, + getFees }; } \ No newline at end of file diff --git a/apps/dapp/src/store/lib/types.ts b/apps/dapp/src/store/lib/types.ts index a699867a..6b21e4e3 100644 --- a/apps/dapp/src/store/lib/types.ts +++ b/apps/dapp/src/store/lib/types.ts @@ -39,7 +39,8 @@ export interface VaultData { TVL: number; totalSupply: number; idleFunds: AssetAmmount[]; - investedFunds: AssetAmmount[] + investedFunds: AssetAmmount[]; + fees: number[]; userBalance?: number; }