From 6761fd975887c70427931ef7be7ba74280488481 Mon Sep 17 00:00:00 2001 From: sebipap Date: Mon, 29 Apr 2024 20:26:01 -0300 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20Leverager:=20fetch=20version?= =?UTF-8?q?=20from=20contract?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contexts/LeveragerContext.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contexts/LeveragerContext.tsx b/contexts/LeveragerContext.tsx index d7c0eb949..b2c88de3c 100644 --- a/contexts/LeveragerContext.tsx +++ b/contexts/LeveragerContext.tsx @@ -55,6 +55,7 @@ import { debtManagerABI } from 'types/abi'; import useStETHNativeAPR from 'hooks/useStETHNativeAPR'; import useIsPermit from 'hooks/useIsPermit'; import { gasLimit } from 'utils/gas'; +import useContractVersion from 'hooks/useContractVersion'; type Params> = AbiParametersToPrimitiveTypes< ExtractAbiFunction['inputs'] @@ -198,6 +199,7 @@ export const LeveragerContextProvider: FC = ({ children }) => const stETHNativeAPR = useStETHNativeAPR(); const minLeverageRatio = 1; + const contractVersion = useContractVersion(); const [leverageStatus, setLeverageStatus] = useState(); @@ -798,7 +800,7 @@ export const LeveragerContextProvider: FC = ({ children }) => primaryType: 'Permit', domain: { name: who.startsWith('market') ? '' : await assetIn.read.name(opts), - version: '1', + version: await contractVersion(verifyingContract), chainId: chain.id, verifyingContract, }, From a229043e18dbfde020693a18e475dacd77aee142 Mon Sep 17 00:00:00 2001 From: franm Date: Thu, 2 May 2024 16:03:04 -0300 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=9A=B8=20leverage:=20show=20an=20erro?= =?UTF-8?q?r=20message=20when=20the=20asset=20is=20not=20collateral?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contexts/LeveragerContext.tsx | 11 +++++++++-- i18n/es/translation.json | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/contexts/LeveragerContext.tsx b/contexts/LeveragerContext.tsx index b2c88de3c..89b659db4 100644 --- a/contexts/LeveragerContext.tsx +++ b/contexts/LeveragerContext.tsx @@ -393,8 +393,14 @@ export const LeveragerContextProvider: FC = ({ children }) => ); const setCollateralSymbol = useCallback( - (collateralSymbol: string) => setBorrowSymbol(collateralSymbol), - [setBorrowSymbol], + (collateralSymbol: string) => { + const marketAccount = getMarketAccount(collateralSymbol); + setBorrowSymbol(collateralSymbol); + if (marketAccount && !marketAccount.isCollateral) { + return setErrorData({ status: true, message: t('Please set this asset as collateral in your dashboard') }); + } + }, + [getMarketAccount, setBorrowSymbol, t], ); const setSecondaryOperation = useCallback((secondaryOperation: 'deposit' | 'withdraw') => { @@ -834,6 +840,7 @@ export const LeveragerContextProvider: FC = ({ children }) => [ assetIn, chain.id, + contractVersion, debtManager, isPermit, maIn, diff --git a/i18n/es/translation.json b/i18n/es/translation.json index b8825c145..1ecbc962f 100644 --- a/i18n/es/translation.json +++ b/i18n/es/translation.json @@ -632,5 +632,6 @@ " In {{installments}} installments": "En {{installments}} cuotas", "Repay Amount": "Monto a Pagar", "Join the waitlist": "Únete a la lista de espera", - "The first onchain debit & credit card.": "La primer tarjeta de débito y crédito onchain." + "The first onchain debit & credit card.": "La primer tarjeta de débito y crédito onchain.", + "Please set this asset as collateral in your dashboard": "Por favor, establece este activo como colateral en tu panel de control" } From a01461a1a1a7ca2930c36dda462e290cbd8bac9a Mon Sep 17 00:00:00 2001 From: franm Date: Mon, 6 May 2024 16:10:15 -0300 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=90=9B=20installments:=20calculate=20?= =?UTF-8?q?installments=20on=20borrowAtMaturity=20only?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contexts/OperationContext.tsx | 1 + hooks/useInstallmentsData.ts | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/contexts/OperationContext.tsx b/contexts/OperationContext.tsx index d390683fb..fc19d3652 100644 --- a/contexts/OperationContext.tsx +++ b/contexts/OperationContext.tsx @@ -122,6 +122,7 @@ export const OperationContextProvider: FC> = ({ args, c const marketContract = useMarket(marketAccount?.market); const ETHRouterContract = useETHRouter(); const { installmentsOptions, installmentsDetails } = useInstallmentsData({ + operation, qty, date, symbol: marketSymbol, diff --git a/hooks/useInstallmentsData.ts b/hooks/useInstallmentsData.ts index 6e07316b5..b6dae7d7a 100644 --- a/hooks/useInstallmentsData.ts +++ b/hooks/useInstallmentsData.ts @@ -6,13 +6,16 @@ import globalUtilization from '@exactly/lib/esm/interest-rate-model/globalUtiliz import useAccountData from 'hooks/useAccountData'; import { INTERVAL } from 'utils/utils'; import useIRM from 'hooks/useIRM'; +import { Operation } from 'types/Operation'; export default function useInstallmentsData({ + operation, qty, date, symbol, installments, }: { + operation: Operation; qty: string; date?: bigint; symbol: string; @@ -23,7 +26,13 @@ export default function useInstallmentsData({ const getDetails = useCallback( (amount: bigint, installments_: bigint, firstMaturity: bigint) => { - if (amount === 0n || irmParameters === undefined || marketAccount === undefined) return; + if ( + amount === 0n || + irmParameters === undefined || + marketAccount === undefined || + operation !== 'borrowAtMaturity' + ) + return; const { floatingUtilization, totalFloatingBorrowAssets, @@ -66,7 +75,7 @@ export default function useInstallmentsData({ effectiveRate, }; }, - [irmParameters, marketAccount], + [irmParameters, marketAccount, operation], ); const installmentsOptions = useMemo(() => {