From 6c59718edffd47cc78c7a268e345217473f45d88 Mon Sep 17 00:00:00 2001 From: shafu Date: Tue, 15 Oct 2024 19:55:21 +0200 Subject: [PATCH 1/3] make it functional --- .gitignore | 2 ++ components/NoteEtensions.tsx | 20 +++++++++++++++++--- constants/NoteCards.ts | 4 ++-- lib/abi/VaultManager.ts | 24 ++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 1a305fc4..a32eb702 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ .env /tags +tags.lock +tags.temp # dependencies /node_modules diff --git a/components/NoteEtensions.tsx b/components/NoteEtensions.tsx index 4c3d2f95..9e448e82 100644 --- a/components/NoteEtensions.tsx +++ b/components/NoteEtensions.tsx @@ -4,17 +4,31 @@ import { Switch } from "@nextui-org/switch"; import NoteCardsContainer from "./reusable/NoteCardsContainer"; import Image from "next/image"; import useWindowSize from "@/hooks/useWindowSize"; +import { useReadVaultManagerIsExtensionAuthorized } from "@/generated"; +import { defaultChain } from "@/lib/config"; +import { useAccount } from "wagmi"; +import ConnectWallet from "./reusable/ConnectWallet"; interface NoteEtensionsProps { extensions: NoteExtensionsModel[]; } const NoteEtensions: React.FC = ({ extensions }) => { + const { address, isConnected } = useAccount(); const [isRedemptionSelected, setRedemptionSelected] = React.useState(false); - const [isNativeEthSelected, setNativeEthSelected] = React.useState(true); + const [isNativeEthSelected, setNativeEthSelected] = React.useState(false); const [isAtomicSwapSelected, setAtomicSwapSelected] = React.useState(false); - const { windowWidth } = useWindowSize(); + + const {data: isNativeEthEnabled} = useReadVaultManagerIsExtensionAuthorized({ + chainId: defaultChain.id, + args: [address, extensions[0].address], + }); + + if (!isConnected) { + return ; + } + return ( <> @@ -60,7 +74,7 @@ const NoteEtensions: React.FC = ({ extensions }) => { extension.label === "Redemption" ? isRedemptionSelected : extension.label === "Native ETH" - ? isNativeEthSelected + ? isNativeEthEnabled : extension.label === "Atomic Swap" ? isAtomicSwapSelected : false diff --git a/constants/NoteCards.ts b/constants/NoteCards.ts index 6734bbea..01e38105 100644 --- a/constants/NoteCards.ts +++ b/constants/NoteCards.ts @@ -4,8 +4,8 @@ export const NOTE_EXTENSIONS = [ { label: "Native ETH", description: "Deposit native ETH into your note without manually wrapping it", - address: "0xDc40", - enabled: false, + address: "0x9F77A6775d6aC6A69107326130D65E422002B5B2", + enabled: true, icon: "/3d-eth.png", }, { diff --git a/lib/abi/VaultManager.ts b/lib/abi/VaultManager.ts index cc943a31..7d461555 100644 --- a/lib/abi/VaultManager.ts +++ b/lib/abi/VaultManager.ts @@ -266,6 +266,30 @@ export const vaultManagerAbi = [ stateMutability: "view", type: "function", }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address" + }, + { + internalType: "address", + name: "extension", + type: "address" + } + ], + name: "isExtensionAuthorized", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool" + } + ], + stateMutability: "view", + type: "function" + }, { inputs: [ { internalType: "uint256", name: "id", type: "uint256" }, From 0f61d6d8a6be3dab0015741755876e38f0c30ccb Mon Sep 17 00:00:00 2001 From: Mostafa Mahmoud Date: Wed, 16 Oct 2024 14:20:47 +0300 Subject: [PATCH 2/3] added a toggle to switch between wETH and ETH if the native ETH extension is enabled --- components/NoteCard/Children/Deposit.tsx | 13 ++++-- components/NoteCard/vaults/Vault.tsx | 51 ++++++++++++++++++----- lib/constants.ts | 17 ++++++-- public/eth.png | Bin 0 -> 6871 bytes 4 files changed, 64 insertions(+), 17 deletions(-) create mode 100644 public/eth.png diff --git a/components/NoteCard/Children/Deposit.tsx b/components/NoteCard/Children/Deposit.tsx index aa89050a..26665dce 100644 --- a/components/NoteCard/Children/Deposit.tsx +++ b/components/NoteCard/Children/Deposit.tsx @@ -26,6 +26,7 @@ const Deposit: React.FC = ({ }) => { const [assetYields, setAssetYields] = useState(); const [selectedKeys, setSelectedKeys] = useState(); + const [isNativeEthActive, setIsNativeEthActive] = useState(false); const { data: vaultData } = useReadContracts({ contracts: supportedVaults.map((address) => ({ @@ -88,11 +89,11 @@ const Deposit: React.FC = ({ const renderVaultTable = (vaultData: VaultInfo[]) => { return (
-
+
{vaultTableHeaders.map((header) => (
{header.label}
@@ -106,11 +107,17 @@ const Deposit: React.FC = ({ ); })} diff --git a/components/NoteCard/vaults/Vault.tsx b/components/NoteCard/vaults/Vault.tsx index 5d927ec8..b55c841f 100644 --- a/components/NoteCard/vaults/Vault.tsx +++ b/components/NoteCard/vaults/Vault.tsx @@ -1,13 +1,10 @@ -import { useEffect, useState } from "react"; +import { Dispatch, SetStateAction, useEffect, useState } from "react"; import Image from "next/image"; import EditVaultModal from "@/components/Modals/NoteCardModals/DepositModals/EditVault/EditVaultModal"; import EditVaultTabContent from "@/components/Modals/NoteCardModals/DepositModals/EditVault/EditVaultTabContent"; import { TabsDataModel } from "@/models/TabsModel"; -import { - Accordion, - AccordionItem, -} from "@nextui-org/accordion"; -import {Tooltip} from "@nextui-org/tooltip"; +import { Accordion, AccordionItem } from "@nextui-org/accordion"; +import { Tooltip } from "@nextui-org/tooltip"; import { VaultInfo, vaultInfo } from "@/lib/constants"; import { defaultChain } from "@/lib/config"; import { Dialog, DialogContent } from "@/components/ui/dialog"; @@ -19,6 +16,7 @@ import { VaultActions } from "@/models/VaultModels"; import { MinusIcon, PlusIcon, XIcon } from "lucide-react"; import useWindowSize from "@/hooks/useWindowSize"; import { Selection } from "@nextui-org/table"; +import { Switch } from "@nextui-org/switch"; const Vault = ({ vault, @@ -27,6 +25,8 @@ const Vault = ({ vaultAssets, selectedKeys, setSelectedKeys, + isNativeEthActive, + setIsNativeEthActive, }: { vault: VaultInfo; tokenId: string; @@ -42,12 +42,16 @@ const Vault = ({ | undefined; selectedKeys: any; setSelectedKeys: (keys: Selection) => any; + isNativeEthActive: boolean; + setIsNativeEthActive: Dispatch>; }) => { const [isEditVaultModalOpen, setIsVaultModalOpen] = useState(false); const [selectedEditVaultTab, setSelectedEditVaultTab] = useState("Deposit"); const [isEditInDialog, setIsEditInDialog] = useState(false); const [vaultInputValue, setVaultInputValue] = useState(""); + //This should be changed to get the real extension status + const isNativeEthExtensionEnabled = true; const { windowWidth } = useWindowSize(); @@ -181,6 +185,15 @@ const Vault = ({
+ {isNativeEthExtensionEnabled && ( + + )}
{ @@ -235,7 +248,7 @@ const Vault = ({ isCompact className="pointer-events-none" title={ -
+
{vaultAssets?.[vault.vaultAddress]?.asset}
-
+
${vaultAssets?.[vault.vaultAddress]?.usdValue}
-
{assetYield}
-
+
{assetYield}
+
+ {isNativeEthExtensionEnabled && ( + + + + )} + Promise; additionalYield?: string; + altCurrencyInfo?: VaultInfo; }; export const vaultInfo: VaultInfo[] = [ @@ -38,6 +39,14 @@ export const vaultInfo: VaultInfo[] = [ tokenAddress: wethAddress[defaultChain.id], color: "#676767", decimals: 8, + altCurrencyInfo: { + icon: "/eth.png", + vaultAddress: wEthVaultAddress[defaultChain.id], + symbol: "ETH", + tokenAddress: wethAddress[defaultChain.id], + color: "#676767", + decimals: 8, + }, }, { icon: "/wsteth.png", @@ -108,10 +117,10 @@ export const vaultInfo: VaultInfo[] = [ tokenAddress: apxEthAddress[defaultChain.id], color: "#aa9a36", decimals: 8, - getApr: async() => { - const resp = await fetch("https://dinero.xyz/api/apr") - const data = await resp.json() + getApr: async () => { + const resp = await fetch("https://dinero.xyz/api/apr"); + const data = await resp.json(); return parseFloat(data.apxEth); - } + }, }, ]; diff --git a/public/eth.png b/public/eth.png new file mode 100644 index 0000000000000000000000000000000000000000..72087661cf214e533d2c4e84f09e6f8d620c27a5 GIT binary patch literal 6871 zcmX9@bzD@>*QS<~r9ogxDJ4~636(CFRq19a$%Uo6yF(C!1(p!xi=ap>C9tG4NG&BT z-6iR}{@y?4&gagYJLh@koafxnog4QWszyo9LXL-rN2#H%tc~mE|20x#+?CaMBn;P) zA=HgL@bD<;{xy8O9OQl6AijsTnj&7+FlY;RLu99*rGST5okDSA3Bbc+an?{)(DlXN z%QHzd)$@*?ey+Dr-#q6%vt-i#I{ID~(Tca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_a_j?8v_g=V!jdr!e^u#QHSAs_~!->W26&Q&EZ zi|%p=kiCEOLw6OzYi7j+inef!t%xAj{P{n>KoZ$0-JiVP7%nVznLjj-=YQs)+|K1= z%#f=*0S`Ag(ipJK)5r^*o5O&=7&$$vz9;+`BVi1H0wHHe0uAT5@pEr60m;Cj_iFXL z=Q&ysM6Axp<9Z5G-W6vCT%^GBReP_BT%2%6KwQ`YIzI9tlSkCk|KqlLI%nQ2d_>nn z#{^R3iTuxn7c_-lb$vIBS z7*7{{$puM|hilb)5jRwZJAt##%qB!)ll%X9xUN}J-`D(^c3M;!t~3fz+{sjC$`km< zd~ZbS`h}6&&xCpkAlF#=gPMN??>x1g)zye%Qa2}X;x5~RhsX#^mRN@?se3vS!Er?E zr5vbPf8vPn$Vjx*cU8L-Gq$_`JED@@z7RqJ%UwrH+H&_Hj?tZwKkqo10LzYERwg_2W}Y-WeDR8Y*z{i zt;u`y1662ZS9)(k3ekC)< zS%npVnAf#W3GH@MOgbHWxH>oeF^#Wl2Sn~q9wMe{wUR!iGGn;t_r9rE%Tb)mqIcg$ zLjF<9tm%Y+Kk&5dmzc1rGdC4cF=ZYX3fpdEdjV}Zo8nb1;EpDY-O)BrIwT?-N^LhZ zS1e@iDLXopq?|olus>7dItj;-*18u@f8zD;)lrTg#b+K((zFni(S0A&xXavl4936>QAB0!R%} z-Cd}>6LubQW5L#+tvsIhfGbklS7L~!iA`yauWnFL+(dla3L=r%4<1IyiBTFRQa6RD zFp1%rGdiBCH7<-7H9fa{NSe_zC$`4~f_SScN450e_%sjtk_Vbc$_%%6`2hSzt8xNs wz2D}E9WxEo;9#@$LB^h*2{2iO#|{3x^0Dz-4LjV8( literal 0 HcmV?d00001 From e90d81b58e3e2445af6e180a815c8087e76eb383 Mon Sep 17 00:00:00 2001 From: Mostafa Mahmoud Date: Wed, 16 Oct 2024 14:54:15 +0300 Subject: [PATCH 3/3] updated the deposit/withdraw form to display the vault symbol conditionally --- components/NoteCard/vaults/Vault.tsx | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/components/NoteCard/vaults/Vault.tsx b/components/NoteCard/vaults/Vault.tsx index b55c841f..758dbf02 100644 --- a/components/NoteCard/vaults/Vault.tsx +++ b/components/NoteCard/vaults/Vault.tsx @@ -65,9 +65,6 @@ const Vault = ({ chainId: defaultChain.id, }); - const { tokenAddress: collateralAddress, symbol: collateralString } = - vaultInfo.filter((value) => value.vaultAddress === vault.vaultAddress)[0]; - const accordionCloseHandler = () => { setSelectedKeys(new Set()); setVaultInputValue(""); @@ -112,8 +109,8 @@ const Vault = ({ content: (