diff --git a/src/components/payments/AssetSelectionSheet.tsx b/src/components/payments/AssetSelectionSheet.tsx index e4a63647..acb673b7 100644 --- a/src/components/payments/AssetSelectionSheet.tsx +++ b/src/components/payments/AssetSelectionSheet.tsx @@ -1,7 +1,7 @@ import type { Address } from "@exactly/common/validation"; import { Coins } from "@tamagui/lucide-icons"; import React from "react"; -import { Sheet, Spinner } from "tamagui"; +import { Sheet } from "tamagui"; import AssetSelector from "../shared/AssetSelector"; import Button from "../shared/Button"; @@ -13,15 +13,12 @@ export default function AssetSelectionSheet({ onClose, onAssetSelected, positions, - symbol, - isSimulating, disabled, }: { open: boolean; onClose: () => void; onAssetSelected: (market: Address) => void; - isSimulating?: boolean; symbol?: string; positions?: { symbol: string; @@ -63,19 +60,14 @@ export default function AssetSelectionSheet({ ); @@ -398,8 +514,8 @@ export default function Pay() { return ( @@ -408,8 +524,8 @@ export default function Pay() { return ( diff --git a/src/components/payments/Pending.tsx b/src/components/payments/Pending.tsx index e1a6fce8..1c785b2a 100644 --- a/src/components/payments/Pending.tsx +++ b/src/components/payments/Pending.tsx @@ -43,11 +43,7 @@ export default function Pending({ showsVerticalScrollIndicator={false} stickyHeaderIndices={[0]} // eslint-disable-next-line react-native/no-inline-styles - contentContainerStyle={{ - flexGrow: 1, - flexDirection: "column", - justifyContent: "space-between", - }} + contentContainerStyle={{ flexGrow: 1, flexDirection: "column", justifyContent: "space-between" }} stickyHeaderHiddenOnScroll > @@ -81,20 +77,11 @@ export default function Pending({ })} - {currency === "USDC" ? ( - - {Number(amount).toLocaleString(undefined, { - maximumFractionDigits: 8, - minimumFractionDigits: 0, - })} - - ) : ( - - Paid with  - - )} - {currency}  + {Number(amount).toLocaleString(undefined, { maximumFractionDigits: 8 })} + + +  {currency}  diff --git a/src/components/payments/Success.tsx b/src/components/payments/Success.tsx index 5bae005f..a0e5cc0d 100644 --- a/src/components/payments/Success.tsx +++ b/src/components/payments/Success.tsx @@ -91,20 +91,11 @@ export default function Success({ })} - {currency === "USDC" ? ( - - {Number(amount).toLocaleString(undefined, { - maximumFractionDigits: 8, - minimumFractionDigits: 0, - })} - - ) : ( - - Paid with  - - )} - {currency}  + {Number(amount).toLocaleString(undefined, { maximumFractionDigits: 8 })} + + +  {currency}  diff --git a/src/utils/lifi.ts b/src/utils/lifi.ts new file mode 100644 index 00000000..8f22f69b --- /dev/null +++ b/src/utils/lifi.ts @@ -0,0 +1,47 @@ +import chain, { mockSwapperAbi, mockSwapperAddress } from "@exactly/common/generated/chain"; +import { Hex } from "@exactly/common/validation"; +import { config, getContractCallsQuote } from "@lifi/sdk"; +import { parse } from "valibot"; +import { encodeFunctionData } from "viem"; +import { optimism, optimismSepolia } from "viem/chains"; + +import publicClient from "./publicClient"; + +async function getRoute(fromToken: Hex, toToken: Hex, toAmount: bigint, account: Hex) { + if (chain.id === optimismSepolia.id) { + const fromAmount = await publicClient.readContract({ + abi: mockSwapperAbi, + functionName: "getAmountIn", + address: parse(Hex, mockSwapperAddress), + args: [fromToken, toAmount, toToken], + }); + return { + fromAmount, + data: parse( + Hex, + encodeFunctionData({ + abi: mockSwapperAbi, + functionName: "swapExactAmountOut", + args: [fromToken, fromAmount, toToken, toAmount], + }), + ), + }; + } + config.set({ integrator: "exa_app", userId: account }); + const { estimate, transactionRequest } = await getContractCallsQuote({ + fee: 0.0025, // TODO review - 0.25% fee + slippage: 0.02, // TODO review - 2% slippage + integrator: "exa_app", + fromChain: optimism.id, + toChain: optimism.id, + fromToken: fromToken.toString(), + toToken: toToken.toString(), + toAmount: toAmount.toString(), + fromAddress: account, + contractCalls: [], + }); + return { fromAmount: BigInt(estimate.fromAmount), data: parse(Hex, transactionRequest?.data) }; +} + +// TODO add necessary exports and remove eslint-disable +export { getRoute }; // eslint-disable-line import/prefer-default-export