@ensofinance/checkout-widget 0.0.14 → 0.0.16
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.
- package/dist/checkout-widget.es.js +7249 -7066
- package/dist/checkout-widget.es.js.map +1 -1
- package/dist/checkout-widget.umd.js +42 -42
- package/dist/checkout-widget.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/CurrencySwapDisplay.tsx +85 -7
- package/src/components/QuoteParameters.tsx +58 -6
- package/src/components/steps/ExchangeFlow.tsx +1 -2
- package/src/components/steps/WalletFlow/WalletAmountStep.tsx +2 -0
- package/src/enso-api/api.ts +42 -0
- package/src/util/common.tsx +3 -0
- package/src/util/enso-hooks.tsx +12 -4
package/package.json
CHANGED
|
@@ -112,17 +112,91 @@ const SwapItem = ({
|
|
|
112
112
|
);
|
|
113
113
|
};
|
|
114
114
|
|
|
115
|
+
// Component for displaying deposit into protocol (non-tokenized positions)
|
|
116
|
+
const DepositItem = ({
|
|
117
|
+
token,
|
|
118
|
+
chainId,
|
|
119
|
+
size = 32,
|
|
120
|
+
}: {
|
|
121
|
+
token: Token;
|
|
122
|
+
chainId?: SupportedChainId;
|
|
123
|
+
size?: number;
|
|
124
|
+
}) => {
|
|
125
|
+
const protocolName = token?.protocolName || token?.protocol;
|
|
126
|
+
const protocolLogo = token?.protocolLogo;
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<Flex align="center" gap={2}>
|
|
130
|
+
<Box position="relative" minW={`${size}px`} minH={`${size}px`}>
|
|
131
|
+
<Box
|
|
132
|
+
borderRadius="50%"
|
|
133
|
+
overflow="hidden"
|
|
134
|
+
width={`${size}px`}
|
|
135
|
+
height={`${size}px`}
|
|
136
|
+
>
|
|
137
|
+
<img
|
|
138
|
+
src={protocolLogo || MOCK_IMAGE_URL}
|
|
139
|
+
title={protocolName}
|
|
140
|
+
alt={protocolName}
|
|
141
|
+
width={`${size}px`}
|
|
142
|
+
height={`${size}px`}
|
|
143
|
+
onError={(e) => {
|
|
144
|
+
e.currentTarget.src = MOCK_IMAGE_URL;
|
|
145
|
+
}}
|
|
146
|
+
/>
|
|
147
|
+
</Box>
|
|
148
|
+
{chainId && (
|
|
149
|
+
<Box
|
|
150
|
+
position="absolute"
|
|
151
|
+
bottom="0"
|
|
152
|
+
right="-2px"
|
|
153
|
+
width={`${size / 2}px`}
|
|
154
|
+
height={`${size / 2}px`}
|
|
155
|
+
borderRadius="50%"
|
|
156
|
+
overflow="hidden"
|
|
157
|
+
border="1px solid white"
|
|
158
|
+
zIndex="1"
|
|
159
|
+
>
|
|
160
|
+
<img
|
|
161
|
+
src={`https://icons-ckg.pages.dev/stargate-light/networks/${STARGATE_CHAIN_NAMES[chainId]}.svg`}
|
|
162
|
+
alt={`Chain ${chainId}`}
|
|
163
|
+
width="100%"
|
|
164
|
+
height="100%"
|
|
165
|
+
/>
|
|
166
|
+
</Box>
|
|
167
|
+
)}
|
|
168
|
+
</Box>
|
|
169
|
+
<Box>
|
|
170
|
+
<Text fontWeight="medium" fontSize="xs" color="fg.muted">
|
|
171
|
+
Deposit{" "}
|
|
172
|
+
<Text as="span" fontSize="xs" color="fg">
|
|
173
|
+
{token?.symbol}
|
|
174
|
+
</Text>
|
|
175
|
+
</Text>
|
|
176
|
+
<Text fontWeight="medium" fontSize="xs" color="fg.muted">
|
|
177
|
+
into{" "}
|
|
178
|
+
<Text as="span" fontSize="xs" color="fg">
|
|
179
|
+
{protocolName}
|
|
180
|
+
</Text>
|
|
181
|
+
</Text>
|
|
182
|
+
</Box>
|
|
183
|
+
</Flex>
|
|
184
|
+
);
|
|
185
|
+
};
|
|
186
|
+
|
|
115
187
|
const CurrencySwapDisplay = ({
|
|
116
188
|
tokenIn,
|
|
117
189
|
tokenOut,
|
|
118
190
|
chainIdIn,
|
|
119
191
|
chainIdOut,
|
|
192
|
+
isNontokenized = false,
|
|
120
193
|
size = 24,
|
|
121
194
|
}: {
|
|
122
195
|
tokenIn: Token;
|
|
123
196
|
tokenOut: Token;
|
|
124
197
|
chainIdIn: number;
|
|
125
198
|
chainIdOut: number;
|
|
199
|
+
isNontokenized?: boolean;
|
|
126
200
|
size?: number;
|
|
127
201
|
}) => {
|
|
128
202
|
return (
|
|
@@ -139,13 +213,17 @@ const CurrencySwapDisplay = ({
|
|
|
139
213
|
width={"16px"}
|
|
140
214
|
height={"16px"}
|
|
141
215
|
/>
|
|
142
|
-
|
|
143
|
-
token={tokenOut}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
216
|
+
{isNontokenized && tokenOut?.protocol ? (
|
|
217
|
+
<DepositItem token={tokenOut} chainId={chainIdOut} size={size} />
|
|
218
|
+
) : (
|
|
219
|
+
<SwapItem
|
|
220
|
+
token={tokenOut}
|
|
221
|
+
chainId={chainIdOut}
|
|
222
|
+
title={"You receive"}
|
|
223
|
+
subTitle={tokenOut?.symbol}
|
|
224
|
+
size={size}
|
|
225
|
+
/>
|
|
226
|
+
)}
|
|
149
227
|
</SwapWrapper>
|
|
150
228
|
);
|
|
151
229
|
};
|
|
@@ -105,6 +105,7 @@ const QuoteParameters = () => {
|
|
|
105
105
|
amountIn,
|
|
106
106
|
chainIdIn,
|
|
107
107
|
selectedIntegration,
|
|
108
|
+
isNontokenized,
|
|
108
109
|
} = useAppDetails();
|
|
109
110
|
const { routeLoading, routeData, routeFetched, routerError } =
|
|
110
111
|
useRouteData();
|
|
@@ -316,7 +317,11 @@ const QuoteParameters = () => {
|
|
|
316
317
|
</Table.Cell>
|
|
317
318
|
</Table.Row>
|
|
318
319
|
<Table.Row>
|
|
319
|
-
<Table.Cell>
|
|
320
|
+
<Table.Cell>
|
|
321
|
+
{isNontokenized && effectiveTokenOutData?.protocol
|
|
322
|
+
? `Deposit into ${effectiveTokenOutData.protocolName || effectiveTokenOutData.protocol}`
|
|
323
|
+
: "You receive"}
|
|
324
|
+
</Table.Cell>
|
|
320
325
|
<Table.Cell
|
|
321
326
|
display="flex"
|
|
322
327
|
textAlign="end"
|
|
@@ -341,11 +346,58 @@ const QuoteParameters = () => {
|
|
|
341
346
|
)}{" "}
|
|
342
347
|
{effectiveTokenOutData?.symbol}
|
|
343
348
|
</Text>
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
+
{isNontokenized && effectiveTokenOutData?.protocol ? (
|
|
350
|
+
<Box
|
|
351
|
+
position="relative"
|
|
352
|
+
minW="24px"
|
|
353
|
+
minH="24px"
|
|
354
|
+
>
|
|
355
|
+
<Box
|
|
356
|
+
borderRadius="50%"
|
|
357
|
+
overflow="hidden"
|
|
358
|
+
width="24px"
|
|
359
|
+
height="24px"
|
|
360
|
+
>
|
|
361
|
+
<img
|
|
362
|
+
src={effectiveTokenOutData.protocolLogo || MOCK_IMAGE_URL}
|
|
363
|
+
title={effectiveTokenOutData.protocol}
|
|
364
|
+
alt={effectiveTokenOutData.protocol}
|
|
365
|
+
width="24px"
|
|
366
|
+
height="24px"
|
|
367
|
+
onError={(e) => {
|
|
368
|
+
e.currentTarget.src = MOCK_IMAGE_URL;
|
|
369
|
+
}}
|
|
370
|
+
/>
|
|
371
|
+
</Box>
|
|
372
|
+
{chainIdOut && (
|
|
373
|
+
<Box
|
|
374
|
+
position="absolute"
|
|
375
|
+
bottom="0"
|
|
376
|
+
right="-2px"
|
|
377
|
+
width="12px"
|
|
378
|
+
height="12px"
|
|
379
|
+
borderRadius="50%"
|
|
380
|
+
overflow="hidden"
|
|
381
|
+
border="1px solid"
|
|
382
|
+
borderColor="bg"
|
|
383
|
+
zIndex="1"
|
|
384
|
+
>
|
|
385
|
+
<img
|
|
386
|
+
src={`https://icons-ckg.pages.dev/stargate-light/networks/${STARGATE_CHAIN_NAMES[chainIdOut]}.svg`}
|
|
387
|
+
alt={`Chain ${chainIdOut}`}
|
|
388
|
+
width="100%"
|
|
389
|
+
height="100%"
|
|
390
|
+
/>
|
|
391
|
+
</Box>
|
|
392
|
+
)}
|
|
393
|
+
</Box>
|
|
394
|
+
) : (
|
|
395
|
+
<TokenIcon
|
|
396
|
+
token={effectiveTokenOutData}
|
|
397
|
+
chainId={chainIdOut}
|
|
398
|
+
size={24}
|
|
399
|
+
/>
|
|
400
|
+
)}
|
|
349
401
|
</Box>
|
|
350
402
|
</Skeleton>
|
|
351
403
|
</Table.Cell>
|
|
@@ -39,6 +39,7 @@ const WalletAmountStep = ({ setStep }: { setStep: (step: string) => void }) => {
|
|
|
39
39
|
tokenIn,
|
|
40
40
|
chainIdOut,
|
|
41
41
|
chainIdIn,
|
|
42
|
+
isNontokenized,
|
|
42
43
|
} = useAppDetails();
|
|
43
44
|
|
|
44
45
|
const { data: priceData } = useEnsoPrice(chainIdIn, tokenIn);
|
|
@@ -199,6 +200,7 @@ const WalletAmountStep = ({ setStep }: { setStep: (step: string) => void }) => {
|
|
|
199
200
|
tokenIn={tokenInData}
|
|
200
201
|
chainIdIn={chainIdIn}
|
|
201
202
|
chainIdOut={chainIdOut}
|
|
203
|
+
isNontokenized={isNontokenized}
|
|
202
204
|
/>
|
|
203
205
|
|
|
204
206
|
<Button
|
package/src/enso-api/api.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
useWalletControllerWalletBalances,
|
|
8
8
|
useNonTokenizedControllerTokens,
|
|
9
9
|
useNontokenizedControllerRouteNontokenizedShorcutTransaction,
|
|
10
|
+
useProtocolsControllerFindAll,
|
|
10
11
|
} from "@/enso-api";
|
|
11
12
|
import { useMemo } from "react";
|
|
12
13
|
import { usePricesControllerGetPrice } from "@/enso-api";
|
|
@@ -19,6 +20,7 @@ import {
|
|
|
19
20
|
RouterControllerRouteShortcutTransactionParams,
|
|
20
21
|
NontokenizedControllerRouteNontokenizedShorcutTransactionParams,
|
|
21
22
|
NonTokenizedModel,
|
|
23
|
+
ProtocolModel,
|
|
22
24
|
} from "./model";
|
|
23
25
|
|
|
24
26
|
export const useWalletBalance = () => {
|
|
@@ -242,6 +244,46 @@ export const useApproveData = ({
|
|
|
242
244
|
return { approveData: res.data, approveFetched: res.isFetched };
|
|
243
245
|
};
|
|
244
246
|
|
|
247
|
+
export const useProtocolsMap = () => {
|
|
248
|
+
const { data, isLoading } = useProtocolsControllerFindAll(
|
|
249
|
+
{},
|
|
250
|
+
{
|
|
251
|
+
query: {
|
|
252
|
+
enabled: true,
|
|
253
|
+
staleTime: 1000 * 60 * 60,
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
const protocolsMap = useMemo(() => {
|
|
259
|
+
if (!data) return new Map<string, ProtocolModel>();
|
|
260
|
+
|
|
261
|
+
const map = new Map<string, ProtocolModel>();
|
|
262
|
+
data.forEach((protocol) => {
|
|
263
|
+
map.set(protocol.slug.toLowerCase(), protocol);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
return map;
|
|
267
|
+
}, [data]);
|
|
268
|
+
|
|
269
|
+
return { protocolsMap, isLoading };
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
export const useProtocolData = (protocolSlug?: string) => {
|
|
273
|
+
const { protocolsMap, isLoading } = useProtocolsMap();
|
|
274
|
+
|
|
275
|
+
const protocolData = useMemo(() => {
|
|
276
|
+
if (!protocolSlug) return null;
|
|
277
|
+
const protocol = protocolsMap.get(protocolSlug.toLowerCase());
|
|
278
|
+
return {
|
|
279
|
+
logoUri: protocol?.logosUri?.[0] || null,
|
|
280
|
+
name: protocol?.name || protocolSlug,
|
|
281
|
+
};
|
|
282
|
+
}, [protocolSlug, protocolsMap]);
|
|
283
|
+
|
|
284
|
+
return { protocolData, isLoading };
|
|
285
|
+
};
|
|
286
|
+
|
|
245
287
|
export const useNontokenizedTokens = () => {
|
|
246
288
|
const config = useConfig();
|
|
247
289
|
|
package/src/util/common.tsx
CHANGED
package/src/util/enso-hooks.tsx
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
useSmartAccountBalance,
|
|
10
10
|
useIsNontokenized,
|
|
11
11
|
useNontokenizedRouteData,
|
|
12
|
+
useProtocolData,
|
|
12
13
|
} from "@/enso-api/api";
|
|
13
14
|
import { getWalletDisplayName, getWalletIcon } from "@/util/wallet";
|
|
14
15
|
import { formatUSD, normalizeValue } from "@/util";
|
|
@@ -98,6 +99,11 @@ export const useAppDetails = () => {
|
|
|
98
99
|
chainIdOut,
|
|
99
100
|
);
|
|
100
101
|
|
|
102
|
+
// Fetch protocol data from Enso API
|
|
103
|
+
const { protocolData } = useProtocolData(
|
|
104
|
+
isNontokenized ? nontokenizedData?.protocol : undefined,
|
|
105
|
+
);
|
|
106
|
+
|
|
101
107
|
// Use underlying tokens if target is nontokenized, otherwise use tokenOutData
|
|
102
108
|
const effectiveTokenOutData = useMemo(() => {
|
|
103
109
|
if (isNontokenized && nontokenizedData?.underlyingTokens) {
|
|
@@ -109,19 +115,21 @@ export const useAppDetails = () => {
|
|
|
109
115
|
}),
|
|
110
116
|
);
|
|
111
117
|
|
|
118
|
+
const protocolName = protocolData?.name || nontokenizedData.protocol;
|
|
119
|
+
|
|
112
120
|
// Return first underlying token as primary, with all underlyingTokens available
|
|
113
121
|
return {
|
|
114
122
|
...underlyingTokens[0],
|
|
115
123
|
underlyingTokens,
|
|
116
124
|
protocol: nontokenizedData.protocol,
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
125
|
+
protocolName,
|
|
126
|
+
protocolLogo: protocolData?.logoUri || undefined,
|
|
127
|
+
name: protocolName + " " + underlyingTokens[0].name,
|
|
120
128
|
};
|
|
121
129
|
}
|
|
122
130
|
|
|
123
131
|
return tokenOutData;
|
|
124
|
-
}, [isNontokenized, nontokenizedData, tokenOutData]);
|
|
132
|
+
}, [isNontokenized, nontokenizedData, tokenOutData, protocolData]);
|
|
125
133
|
|
|
126
134
|
const nontokenizedPrice = useEnsoPrice(
|
|
127
135
|
chainIdOut,
|