@ensofinance/checkout-widget 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/dist/checkout-widget.es.js +52889 -0
  2. package/dist/checkout-widget.es.js.map +1 -0
  3. package/dist/checkout-widget.umd.js +203 -0
  4. package/dist/checkout-widget.umd.js.map +1 -0
  5. package/dist/index.d.ts +23 -0
  6. package/enso-api.yaml +1982 -0
  7. package/orval.config.ts +25 -0
  8. package/package.json +79 -0
  9. package/src/assets/BinanceBadge.svg +4 -0
  10. package/src/assets/CoinbaseIcon.svg +4 -0
  11. package/src/assets/USD Coin (USDC).svg +5 -0
  12. package/src/assets/avecIcon.svg +5 -0
  13. package/src/assets/base.webp +0 -0
  14. package/src/assets/depositIcon.svg +6 -0
  15. package/src/assets/eth.webp +0 -0
  16. package/src/assets/ethMainnetIcon.svg +10 -0
  17. package/src/assets/fail.svg +5 -0
  18. package/src/assets/kraken.png +0 -0
  19. package/src/assets/logo.svg +10 -0
  20. package/src/assets/mastercard.png +0 -0
  21. package/src/assets/metamask.png +0 -0
  22. package/src/assets/rabby.png +0 -0
  23. package/src/assets/success.svg +4 -0
  24. package/src/assets/usdc.webp +0 -0
  25. package/src/assets/usdt.webp +0 -0
  26. package/src/assets/visa.png +0 -0
  27. package/src/assets/visa.webp +0 -0
  28. package/src/components/BridgeFee.tsx +58 -0
  29. package/src/components/ChakraProvider.tsx +372 -0
  30. package/src/components/Checkout.tsx +127 -0
  31. package/src/components/CheckoutModal.tsx +22 -0
  32. package/src/components/CircleTimer.tsx +66 -0
  33. package/src/components/CurrencySwapDisplay.tsx +153 -0
  34. package/src/components/DepositProcessing.tsx +116 -0
  35. package/src/components/ExchangeConfirmSecurity.tsx +110 -0
  36. package/src/components/QuoteParameters.tsx +341 -0
  37. package/src/components/TransactionDetailRow.tsx +124 -0
  38. package/src/components/cards/AssetCard.tsx +167 -0
  39. package/src/components/cards/ExchangeCard.tsx +53 -0
  40. package/src/components/cards/OptionCard.tsx +59 -0
  41. package/src/components/cards/WalletCard.tsx +99 -0
  42. package/src/components/cards/index.ts +6 -0
  43. package/src/components/modal.tsx +83 -0
  44. package/src/components/steps/ExchangeFlow.tsx +1402 -0
  45. package/src/components/steps/InitialStep.tsx +169 -0
  46. package/src/components/steps/QuoteStep.tsx +121 -0
  47. package/src/components/steps/WalletAmountStep.tsx +258 -0
  48. package/src/components/steps/WalletConfirmStep.tsx +404 -0
  49. package/src/components/steps/WalletTokenStep.tsx +128 -0
  50. package/src/components/ui/index.tsx +394 -0
  51. package/src/components/ui/styled.tsx +85 -0
  52. package/src/components/ui/toaster.tsx +43 -0
  53. package/src/components/ui/tooltip.tsx +46 -0
  54. package/src/enso-api/api.ts +173 -0
  55. package/src/enso-api/custom-instance.ts +35 -0
  56. package/src/enso-api/index.ts +5119 -0
  57. package/src/enso-api/model/action.ts +17 -0
  58. package/src/enso-api/model/actionAction.ts +52 -0
  59. package/src/enso-api/model/actionInputs.ts +12 -0
  60. package/src/enso-api/model/actionToBundle.ts +19 -0
  61. package/src/enso-api/model/actionToBundleAction.ts +53 -0
  62. package/src/enso-api/model/actionToBundleArgs.ts +12 -0
  63. package/src/enso-api/model/bundleControllerBundleShortcutTransactionParams.ts +53 -0
  64. package/src/enso-api/model/bundleControllerBundleShortcutTransactionRoutingStrategy.ts +23 -0
  65. package/src/enso-api/model/bundleShortcutTransaction.ts +35 -0
  66. package/src/enso-api/model/bundleShortcutTransactionAmountsOut.ts +15 -0
  67. package/src/enso-api/model/bundleShortcutTransactionFeeAmount.ts +12 -0
  68. package/src/enso-api/model/connectedNetwork.ts +16 -0
  69. package/src/enso-api/model/hop.ts +24 -0
  70. package/src/enso-api/model/hopArgs.ts +12 -0
  71. package/src/enso-api/model/index.ts +70 -0
  72. package/src/enso-api/model/iporControllerIporShortcutTransactionParams.ts +21 -0
  73. package/src/enso-api/model/iporShortcutInput.ts +33 -0
  74. package/src/enso-api/model/iporShortcutTransaction.ts +22 -0
  75. package/src/enso-api/model/lZDestinationTokenData.ts +19 -0
  76. package/src/enso-api/model/lZPoolLookupResponse.ts +26 -0
  77. package/src/enso-api/model/layerZeroControllerGetPoolAddressParams.ts +29 -0
  78. package/src/enso-api/model/network.ts +15 -0
  79. package/src/enso-api/model/networksControllerNetworksParams.ts +21 -0
  80. package/src/enso-api/model/nonTokenizedControllerTokens200.ts +15 -0
  81. package/src/enso-api/model/nonTokenizedControllerTokens200AllOf.ts +16 -0
  82. package/src/enso-api/model/nonTokenizedControllerTokensParams.ts +41 -0
  83. package/src/enso-api/model/nonTokenizedModel.ts +27 -0
  84. package/src/enso-api/model/nontokenizedControllerRouteNontokenizedShorcutTransactionParams.ts +64 -0
  85. package/src/enso-api/model/nontokenizedControllerRouteNontokenizedShorcutTransactionRoutingStrategy.ts +22 -0
  86. package/src/enso-api/model/paginatedResult.ts +16 -0
  87. package/src/enso-api/model/paginationMeta.ts +27 -0
  88. package/src/enso-api/model/positionModel.ts +77 -0
  89. package/src/enso-api/model/price.ts +20 -0
  90. package/src/enso-api/model/pricesControllerGetPricesParams.ts +17 -0
  91. package/src/enso-api/model/project.ts +15 -0
  92. package/src/enso-api/model/protocol.ts +15 -0
  93. package/src/enso-api/model/protocolModel.ts +26 -0
  94. package/src/enso-api/model/protocolsControllerFindAllParams.ts +21 -0
  95. package/src/enso-api/model/routeShortcutTransaction.ts +33 -0
  96. package/src/enso-api/model/routeShortcutVariableInputs.ts +68 -0
  97. package/src/enso-api/model/routeShortcutVariableInputsRoutingStrategy.ts +27 -0
  98. package/src/enso-api/model/routeShortcutVariableInputsVariableEstimates.ts +14 -0
  99. package/src/enso-api/model/routerControllerRouteShortcutTransactionParams.ts +91 -0
  100. package/src/enso-api/model/routerControllerRouteShortcutTransactionRoutingStrategy.ts +23 -0
  101. package/src/enso-api/model/standard.ts +18 -0
  102. package/src/enso-api/model/standardAction.ts +20 -0
  103. package/src/enso-api/model/standardActionAction.ts +53 -0
  104. package/src/enso-api/model/tokenModel.ts +36 -0
  105. package/src/enso-api/model/tokensControllerTokens200.ts +15 -0
  106. package/src/enso-api/model/tokensControllerTokens200AllOf.ts +16 -0
  107. package/src/enso-api/model/tokensControllerTokensParams.ts +91 -0
  108. package/src/enso-api/model/tokensControllerTokensType.ts +19 -0
  109. package/src/enso-api/model/transaction.ts +17 -0
  110. package/src/enso-api/model/userOperation.ts +28 -0
  111. package/src/enso-api/model/walletApproveTransaction.ts +24 -0
  112. package/src/enso-api/model/walletApproveTransactionTx.ts +15 -0
  113. package/src/enso-api/model/walletBalance.ts +29 -0
  114. package/src/enso-api/model/walletControllerCreateApproveTransactionParams.ts +35 -0
  115. package/src/enso-api/model/walletControllerCreateApproveTransactionRoutingStrategy.ts +23 -0
  116. package/src/enso-api/model/walletControllerWalletBalancesParams.ts +25 -0
  117. package/src/index.ts +17 -0
  118. package/src/store.ts +68 -0
  119. package/src/types/assets.d.ts +29 -0
  120. package/src/types/index.ts +21 -0
  121. package/src/util/common.tsx +324 -0
  122. package/src/util/constants.tsx +213 -0
  123. package/src/util/enso-hooks.tsx +203 -0
  124. package/src/util/index.tsx +68 -0
  125. package/src/util/tx-tracker.tsx +301 -0
  126. package/src/util/wallet.tsx +258 -0
  127. package/tsconfig.json +13 -0
  128. package/vite.config.ts +51 -0
@@ -0,0 +1,258 @@
1
+ import {
2
+ ReactElement,
3
+ ReactNode,
4
+ useCallback,
5
+ useEffect,
6
+ useState,
7
+ } from "react";
8
+ import {
9
+ useAccount,
10
+ useBalance,
11
+ useReadContract,
12
+ useSendTransaction,
13
+ UseSimulateContractParameters,
14
+ } from "wagmi";
15
+ import { Address, isAddress, erc20Abi } from "viem";
16
+ import { WalletIcon } from "lucide-react";
17
+ import { useQueryClient } from "@tanstack/react-query";
18
+ import { RouteData } from "@ensofinance/sdk";
19
+ import { usePriorityChainId } from "./common";
20
+ import { ETH_ADDRESS, SupportedChainId } from "@/util/constants";
21
+ import { compareCaseInsensitive } from "@/util/index";
22
+ import { toaster } from "@/components/ui/toaster";
23
+
24
+ import metamaskIcon from "@/assets/metamask.png";
25
+ import rabbyIcon from "@/assets/rabby.png";
26
+
27
+ enum TxState {
28
+ Success,
29
+ Failure,
30
+ Pending,
31
+ }
32
+
33
+ export const toastState: Record<TxState, "success" | "error" | "info"> = {
34
+ [TxState.Success]: "success",
35
+ [TxState.Failure]: "error",
36
+ [TxState.Pending]: "info",
37
+ };
38
+
39
+ const useInterval = (callback: () => void, interval: number) => {
40
+ const savedCallback = useCallback(callback, []);
41
+
42
+ useEffect(() => {
43
+ const id = setInterval(savedCallback, interval);
44
+ return () => clearInterval(id);
45
+ }, [interval, savedCallback]);
46
+ };
47
+ const useChangingIndex = () => {
48
+ const [index, setIndex] = useState(0);
49
+
50
+ useInterval(() => {
51
+ setIndex(index + 1);
52
+ }, 10000);
53
+
54
+ return index;
55
+ };
56
+
57
+ export const useErc20Balance = (
58
+ tokenAddress: `0x${string}`,
59
+ priorityChainId?: SupportedChainId,
60
+ ) => {
61
+ const { address } = useAccount();
62
+ const chainId = usePriorityChainId(priorityChainId);
63
+
64
+ return useReadContract({
65
+ chainId,
66
+ address: tokenAddress,
67
+ abi: erc20Abi,
68
+ functionName: "balanceOf",
69
+ args: [address],
70
+ query: {
71
+ enabled:
72
+ isAddress(address) &&
73
+ isAddress(tokenAddress) &&
74
+ !compareCaseInsensitive(tokenAddress, ETH_ADDRESS),
75
+ },
76
+ });
77
+ };
78
+
79
+ // if token is native ETH, use usBalance instead
80
+ export const useTokenBalance = (
81
+ token: Address,
82
+ priorityChainId?: SupportedChainId,
83
+ ) => {
84
+ const { address } = useAccount();
85
+ const chainId = usePriorityChainId(priorityChainId);
86
+ const index = useChangingIndex();
87
+ const queryClient = useQueryClient();
88
+ const { data: erc20Balance, queryKey: erc20QueryKey } = useErc20Balance(
89
+ token,
90
+ priorityChainId,
91
+ );
92
+ const { data: balance, queryKey: balanceQueryKey } = useBalance({
93
+ address,
94
+ chainId,
95
+ query: {
96
+ enabled: compareCaseInsensitive(token, ETH_ADDRESS),
97
+ },
98
+ });
99
+
100
+ useEffect(() => {
101
+ queryClient.invalidateQueries({ queryKey: erc20QueryKey });
102
+ queryClient.invalidateQueries({ queryKey: balanceQueryKey });
103
+ }, [index, queryClient, erc20QueryKey, balanceQueryKey]);
104
+
105
+ const value = compareCaseInsensitive(token, ETH_ADDRESS)
106
+ ? balance?.value
107
+ : erc20Balance;
108
+
109
+ return value?.toString() ?? "0";
110
+ };
111
+
112
+ export const useAllowance = (token: Address, spender: Address) => {
113
+ const { address } = useAccount();
114
+ const chainId = usePriorityChainId();
115
+ const index = useChangingIndex();
116
+ const queryClient = useQueryClient();
117
+ const { data, queryKey, isLoading, isFetched } = useReadContract({
118
+ chainId,
119
+ address: token,
120
+ abi: erc20Abi,
121
+ functionName: "allowance",
122
+ args: [address, spender],
123
+ query: {
124
+ enabled:
125
+ isAddress(address) &&
126
+ isAddress(token) &&
127
+ !compareCaseInsensitive(token, ETH_ADDRESS),
128
+ },
129
+ });
130
+
131
+ useEffect(() => {
132
+ queryClient.invalidateQueries({ queryKey });
133
+ }, [index, queryClient, queryKey]);
134
+
135
+ return {
136
+ allowance: data?.toString() ?? "0",
137
+ allowanceFetched: isFetched,
138
+ allowanceLoading: isLoading,
139
+ };
140
+ };
141
+
142
+ export const useExtendedSendTransaction = ({
143
+ title,
144
+ args,
145
+ onSuccess,
146
+ crosschain,
147
+ }: {
148
+ title: string;
149
+ args: UseSimulateContractParameters;
150
+ onSuccess?: (hash: string) => void;
151
+ crosschain?: boolean;
152
+ }) => {
153
+ const sendTransaction = useSendTransaction();
154
+
155
+ const send = useCallback(() => {
156
+ sendTransaction.sendTransaction(args, {
157
+ onError: (error) => {
158
+ toaster.create({
159
+ title: "Error",
160
+ // @ts-ignore
161
+ description: error?.cause?.shortMessage || error.message,
162
+ type: "error",
163
+ });
164
+ console.error(error);
165
+ },
166
+ onSuccess,
167
+ });
168
+ }, [sendTransaction, args, onSuccess]);
169
+
170
+ return {
171
+ ...sendTransaction,
172
+ send,
173
+ };
174
+ };
175
+
176
+ export const useIsApproveNeeded = (
177
+ tokenIn: Address,
178
+ target: Address = "0xF75584eF6673aD213a685a1B58Cc0330B8eA22Cf",
179
+ amount: string,
180
+ ) => {
181
+ const { allowance, allowanceFetched, allowanceLoading } = useAllowance(
182
+ tokenIn,
183
+ target,
184
+ );
185
+
186
+ const approveNeeded =
187
+ !compareCaseInsensitive(tokenIn, ETH_ADDRESS) && +allowance < +amount;
188
+
189
+ return {
190
+ approveNeeded,
191
+ allowanceFetched,
192
+ allowanceLoading,
193
+ };
194
+ };
195
+
196
+ export const useSendEnsoTransaction = ({
197
+ args,
198
+ title,
199
+ crosschain,
200
+ onSuccess,
201
+ }: {
202
+ args: RouteData["tx"];
203
+ title: string;
204
+ crosschain?: boolean;
205
+ onSuccess?: (hash: string) => void;
206
+ }) => {
207
+ return useExtendedSendTransaction({
208
+ title,
209
+ args,
210
+ crosschain,
211
+ onSuccess,
212
+ });
213
+ };
214
+
215
+ /**
216
+ * Get the appropriate wallet icon based on the connector name
217
+ * @param connectorName - The name of the wallet connector
218
+ * @returns The icon path for the wallet
219
+ */
220
+ export const getWalletIcon = (
221
+ connectorName?: string,
222
+ ): string | ReactElement => {
223
+ if (!connectorName) return metamaskIcon; // Default fallback
224
+
225
+ const name = connectorName.toLowerCase();
226
+
227
+ // MetaMask variants
228
+ if (name.includes("metamask")) {
229
+ return metamaskIcon;
230
+ }
231
+
232
+ // Rabby wallet
233
+ if (name.includes("rabby")) {
234
+ return rabbyIcon;
235
+ }
236
+
237
+ // Default fallback for unknown wallets
238
+ return <WalletIcon size={20} />;
239
+ };
240
+
241
+ /**
242
+ * Get a user-friendly wallet name for display
243
+ * @param connectorName - The name of the wallet connector
244
+ * @returns A formatted wallet name
245
+ */
246
+ export const getWalletDisplayName = (connectorName?: string): string => {
247
+ if (!connectorName) return "Wallet";
248
+
249
+ const name = connectorName.toLowerCase();
250
+
251
+ if (name.includes("metamask")) return "MetaMask";
252
+ if (name.includes("rabby")) return "Rabby";
253
+ if (name.includes("walletconnect")) return "WalletConnect";
254
+ if (name.includes("injected")) return "Browser Wallet";
255
+
256
+ // Return the original name with proper capitalization
257
+ return connectorName.charAt(0).toUpperCase() + connectorName.slice(1);
258
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "skipLibCheck": true,
7
+ "paths": {
8
+ "@/*": ["./src/*"]
9
+ },
10
+ "jsx": "react-jsx",
11
+ "declaration": true
12
+ }
13
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,51 @@
1
+ import { defineConfig } from "vite";
2
+ import react from "@vitejs/plugin-react";
3
+ import dts from "vite-plugin-dts";
4
+
5
+ export default defineConfig(({ mode }) => ({
6
+ plugins: [
7
+ mode === "development" ? react() : undefined,
8
+ dts({
9
+ insertTypesEntry: true,
10
+ rollupTypes: true,
11
+ bundledPackages: ["./src/types"],
12
+ }), // generates *.d.ts beside the JS
13
+ ].filter(Boolean),
14
+ resolve: {
15
+ alias: {
16
+ "@": "/src",
17
+ },
18
+ },
19
+ build: {
20
+ lib: {
21
+ entry: "./src/index.ts", // Entry point for your component
22
+ name: "CheckoutWidget", // Global name for UMD builds
23
+ fileName: (format) => `checkout-widget.${format}.js`, // Output file naming
24
+ },
25
+ rollupOptions: {
26
+ external: [
27
+ /^wagmi($|\/)/,
28
+ /^react($|\/)/,
29
+ /^react-dom($|\/)/, // removes legacy react-dom/server
30
+ "react",
31
+ "react-dom",
32
+ "wagmi",
33
+ "@tanstack/react-query",
34
+ "react/jsx-runtime",
35
+ "react/jsx-dev-runtime",
36
+ ],
37
+ output: {
38
+ globals: {
39
+ react: "React",
40
+ "react-dom": "ReactDOM",
41
+ "react/jsx-runtime": "ReactJsxRuntime",
42
+ },
43
+ },
44
+ },
45
+ sourcemap: true,
46
+ target: "es2018",
47
+ },
48
+ esbuild: {
49
+ jsxImportSource: "react",
50
+ },
51
+ }));