@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,173 @@
1
+ import { useAccount } from "wagmi";
2
+ import {
3
+ useRouterControllerPostRouteShortcutTransaction,
4
+ useRouterControllerRouteShortcutTransaction,
5
+ useTokensControllerTokens,
6
+ useWalletControllerCreateApproveTransaction,
7
+ useWalletControllerWalletBalances,
8
+ } from "@/enso-api";
9
+ import { useMemo } from "react";
10
+ import { usePricesControllerGetPrice } from "@/enso-api";
11
+ import { Token } from "@/util/common";
12
+ import { useAppStore } from "@/store";
13
+ import { Address } from "viem";
14
+ import { formatNumber, normalizeValue } from "@/util";
15
+ import { VITALIK_ADDRESS } from "@/util/constants";
16
+ import { RouterControllerRouteShortcutTransactionParams } from "./model";
17
+
18
+ export const useWalletBalance = () => {
19
+ const { address } = useAccount();
20
+ const ensoApiToken = useAppStore((state) => state.ensoApiToken);
21
+
22
+ const { data, isLoading } = useWalletControllerWalletBalances(
23
+ {
24
+ eoaAddress: address,
25
+ // @ts-ignore
26
+ chainId: "all",
27
+ // chainId: 8453,
28
+ },
29
+ {
30
+ query: {
31
+ enabled: !!address && !!ensoApiToken,
32
+ },
33
+ },
34
+ );
35
+
36
+ const { holdingsList, total } = useMemo(() => {
37
+ if (!data?.length) return { holdingsList: [], total: 0 };
38
+
39
+ const holdingsList = data
40
+ ?.map((balanace) => ({
41
+ ...balanace,
42
+ total:
43
+ (+balanace.amount / 10 ** balanace.decimals) *
44
+ +balanace.price,
45
+ }))
46
+ .filter((balance) => balance.total > 1 && balance.total < 10000)
47
+ .sort((a, b) => b.total - a.total);
48
+
49
+ const total = holdingsList?.reduce((acc, { total }) => acc + total, 0);
50
+
51
+ return { holdingsList, total };
52
+ }, [data]);
53
+
54
+ return { holdingsList, total, isLoading };
55
+ };
56
+
57
+ const mapTokenData = (tokenData: any): Token => ({
58
+ ...tokenData,
59
+ logoURI: tokenData?.logosUri?.[0],
60
+ underlyingTokens: tokenData?.underlyingTokens?.map(mapTokenData),
61
+ });
62
+
63
+ //immutable array
64
+ const MOCK_ARRAY = [];
65
+
66
+ export const useEnsoToken = (token: string, chainId: number) => {
67
+ const { data, isLoading } = useTokensControllerTokens(
68
+ { address: [token], chainId, includeMetadata: true },
69
+ { query: { enabled: !!token && !!chainId } },
70
+ );
71
+
72
+ return {
73
+ data: data?.data?.length ? data?.data?.map(mapTokenData) : MOCK_ARRAY,
74
+ isLoading,
75
+ };
76
+ };
77
+
78
+ export const useEnsoPrice = (chainId: number, token: string) => {
79
+ const { data, isLoading } = usePricesControllerGetPrice(chainId, token);
80
+
81
+ return { data: data?.price, isLoading };
82
+ };
83
+
84
+ export const useEnsoData = ({
85
+ chainId,
86
+ outChainId,
87
+ fromAddress,
88
+ receiver,
89
+ spender,
90
+ amountIn,
91
+ tokenIn,
92
+ tokenOut,
93
+ slippage,
94
+ referralCode,
95
+ routingStrategy = "router",
96
+ }: {
97
+ chainId: number;
98
+ outChainId: number;
99
+ fromAddress: string;
100
+ receiver: string;
101
+ spender: string;
102
+ amountIn: string;
103
+ tokenIn: string;
104
+ tokenOut: string;
105
+ slippage: number;
106
+ referralCode?: string;
107
+ routingStrategy?: "router" | "checkout";
108
+ }) => {
109
+ const routerParams: RouterControllerRouteShortcutTransactionParams = {
110
+ referralCode,
111
+ amountIn: [amountIn],
112
+ tokenIn: [tokenIn],
113
+ tokenOut: [tokenOut],
114
+ slippage: slippage.toString(),
115
+ fromAddress,
116
+ receiver,
117
+ spender,
118
+ // @ts-ignore
119
+ routingStrategy,
120
+ chainId,
121
+ };
122
+
123
+ let isCrosschain = outChainId !== chainId;
124
+
125
+ if (isCrosschain) {
126
+ routerParams.destinationChainId = outChainId;
127
+ }
128
+
129
+ const {
130
+ data: [tokenToData],
131
+ } = useEnsoToken(tokenOut, outChainId);
132
+ const {
133
+ data: [tokenFromData],
134
+ } = useEnsoToken(tokenIn, chainId);
135
+
136
+ const swapTitle = `Purchase ${formatNumber(
137
+ normalizeValue(amountIn, tokenFromData?.decimals),
138
+ )} ${tokenFromData?.symbol} of ${tokenToData?.symbol}`;
139
+
140
+ const routerData = useRouterControllerRouteShortcutTransaction(
141
+ routerParams,
142
+ {
143
+ query: {
144
+ retry: 2,
145
+ enabled:
146
+ !!routerParams.amountIn && !!tokenFromData && !!tokenToData,
147
+ },
148
+ },
149
+ );
150
+
151
+ return { ...routerData, title: swapTitle };
152
+ };
153
+
154
+ export const useApproveData = ({
155
+ address,
156
+ token,
157
+ chainId,
158
+ amount,
159
+ }: {
160
+ address: string;
161
+ token: string;
162
+ chainId: number;
163
+ amount: string;
164
+ }) => {
165
+ const res = useWalletControllerCreateApproveTransaction({
166
+ fromAddress: address,
167
+ tokenAddress: token,
168
+ chainId,
169
+ amount,
170
+ });
171
+
172
+ return { approveData: res.data, approveFetched: res.isFetched };
173
+ };
@@ -0,0 +1,35 @@
1
+ // import Axios from "axios";
2
+ import { useAppStore } from "@/store";
3
+
4
+ // export const AXIOS_INSTANCE = Axios.create({
5
+ // baseURL: "https://api.enso.finance",
6
+ // });
7
+
8
+ type CustomClient<T> = (data: {
9
+ url: string;
10
+ method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
11
+ params?: Record<string, any>;
12
+ headers?: Record<string, any>;
13
+ data?: BodyType<unknown>;
14
+ signal?: AbortSignal;
15
+ }) => Promise<T>;
16
+
17
+ export const useCustomClient = <T>(): CustomClient<T> => {
18
+ const token = useAppStore((state) => state.ensoApiToken);
19
+
20
+ return async ({ url, method, params, data }) => {
21
+ const response = await fetch(url + "?" + new URLSearchParams(params), {
22
+ method,
23
+ headers: { ...data?.headers, Authorization: `Bearer ${token}` },
24
+ ...(data ? { body: JSON.stringify(data) } : {}),
25
+ });
26
+
27
+ return response.json();
28
+ };
29
+ };
30
+
31
+ export default useCustomClient;
32
+
33
+ export type ErrorType<ErrorData> = ErrorData;
34
+
35
+ export type BodyType<BodyData> = BodyData & { headers?: any };