Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add defindex & vault fees on inspect modal #239

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/dapp/src/components/DeployVault/ConfirmDelpoyModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand All @@ -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));
Expand Down
11 changes: 10 additions & 1 deletion apps/dapp/src/components/ManageVaults/InspectVault.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const InspectVault = ({
<Stack>
<Text>Strategies:</Text>
{selectedVault.assets.map((asset: Asset, index: number) => (
<Stack>
<Stack key={index}>
<For each={asset.strategies}>
{(strategy: Strategy, index: number) => (
<HStack key={index} alignContent={'center'}>
Expand Down Expand Up @@ -109,6 +109,15 @@ export const InspectVault = ({
</HStack>
))}
</Stack>
<Stack>
<Text>Fees:</Text>
<Text>
Defindex fee: {(selectedVault.fees[0]! / 100).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits: 2 })} %
</Text>
<Text>
Vault fee: {(selectedVault.fees[1]! / 100).toLocaleString('en-US', { style: 'decimal', maximumFractionDigits: 2 })} %
</Text>
</Stack>
{(address && selectedVault.userBalance) &&
<Stack>
<Text>User balance:</Text>
Expand Down
10 changes: 9 additions & 1 deletion apps/dapp/src/components/ManageVaults/ManageVaults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ export const ManageVaults = () => {
<DeployVault />
</DialogRoot>}
</GridItem>

{/* Interact with vault */}
<GridItem colSpan={12} colStart={1} colEnd={13} zIndex={'base'}>
<DialogRoot
open={interactModal.isOpen}
Expand All @@ -149,10 +151,12 @@ export const ManageVaults = () => {
</DialogRoot>
<AllVaults handleOpenInspect={handleInspectVault} />
</GridItem>

{/* Inspect vault */}
<DialogRoot
open={inspectModal.isOpen}
onOpenChange={(e) => { inspectModal.setIsOpen(e.open) }}
size={'lg'}
size={'xl'}
placement={'center'}
>
<DialogBackdrop backdropFilter='blur(1px)' />
Expand All @@ -162,6 +166,8 @@ export const ManageVaults = () => {
onClose={() => { inspectModal.setIsOpen(false) }}
/>
</DialogRoot>

{/* Edit vault */}
<DialogRoot
open={editModal.isOpen}
onOpenChange={(e) => { editModal.setIsOpen(e.open) }}
Expand All @@ -171,6 +177,8 @@ export const ManageVaults = () => {
<DialogBackdrop backdropFilter='blur(1px)' />
<EditVaultModal />
</DialogRoot>

{/* Transaction status modal */}
<DialogRoot
open={modalContext.transactionStatusModal.isOpen}
onOpenChange={(e) => { txModal.setIsOpen(e.open) }}
Expand Down
19 changes: 16 additions & 3 deletions apps/dapp/src/hooks/useVault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -67,7 +68,8 @@ export const useVault = (vaultAddress?: string | undefined) => {
TVL,
totalSupply,
idleFunds,
investedFunds
investedFunds,
fees
] = await Promise.all([
getVaultManager(vaultAddress),
getVaultEmergencyManager(vaultAddress),
Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -215,6 +227,7 @@ export const useVault = (vaultAddress?: string | undefined) => {
getUserBalance,
getTVL,
getIdleFunds,
getInvestedFunds,
getInvestedFunds,
getFees
};
}
3 changes: 2 additions & 1 deletion apps/dapp/src/store/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export interface VaultData {
TVL: number;
totalSupply: number;
idleFunds: AssetAmmount[];
investedFunds: AssetAmmount[]
investedFunds: AssetAmmount[];
fees: number[];
userBalance?: number;
}

Expand Down