@rango-dev/widget-embedded 0.14.1-next.1 → 0.14.1-next.10
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/Widget.d.ts.map +1 -1
- package/dist/components/BlockchainList/BlockchainList.styles.d.ts +8 -0
- package/dist/components/BlockchainList/BlockchainList.styles.d.ts.map +1 -1
- package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts +4 -0
- package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +60 -0
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts +12 -0
- package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts.map +1 -1
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +16 -0
- package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
- package/dist/components/Layout/Layout.styles.d.ts +12 -0
- package/dist/components/Layout/Layout.styles.d.ts.map +1 -1
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts +4 -0
- package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts.map +1 -1
- package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts +12 -0
- package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts.map +1 -1
- package/dist/components/NoRoutes/NoRoutes.styles.d.ts +12 -0
- package/dist/components/NoRoutes/NoRoutes.styles.d.ts.map +1 -1
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts +16 -0
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +1 -1
- package/dist/components/RouteErrors/RouteErrors.styles.d.ts +16 -0
- package/dist/components/RouteErrors/RouteErrors.styles.d.ts.map +1 -1
- package/dist/components/SearchInput/SearchInput.styles.d.ts +4 -0
- package/dist/components/SearchInput/SearchInput.styles.d.ts.map +1 -1
- package/dist/components/SettingsContainer/SettingsContainer.style.d.ts +16 -0
- package/dist/components/SettingsContainer/SettingsContainer.style.d.ts.map +1 -1
- package/dist/components/Slippage/Slippage.styles.d.ts +16 -0
- package/dist/components/Slippage/Slippage.styles.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts +24 -0
- package/dist/components/SwapDetails/SwapDetails.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts +4 -0
- package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts +4 -0
- package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts.map +1 -1
- package/dist/components/SwapsGroup/SwapsGroup.styles.d.ts +16 -0
- package/dist/components/SwapsGroup/SwapsGroup.styles.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.styles.d.ts +40 -0
- package/dist/components/TokenList/TokenList.styles.d.ts.map +1 -1
- package/dist/components/WalletModal/WalletModalContent.styles.d.ts +16 -0
- package/dist/components/WalletModal/WalletModalContent.styles.d.ts.map +1 -1
- package/dist/constants/fonts.d.ts +2 -0
- package/dist/constants/fonts.d.ts.map +1 -0
- package/dist/{constants.d.ts → constants/index.d.ts} +1 -1
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/hooks/useTheme.d.ts +2 -2
- package/dist/hooks/useTheme.d.ts.map +1 -1
- package/dist/index.d.ts +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/store/bestRoute.d.ts.map +1 -1
- package/dist/types/config.d.ts +5 -10
- package/dist/types/config.d.ts.map +1 -1
- package/dist/utils/colors.d.ts +11 -0
- package/dist/utils/colors.d.ts.map +1 -0
- package/dist/utils/common.d.ts +0 -4
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/configs.d.ts +2 -0
- package/dist/utils/configs.d.ts.map +1 -1
- package/dist/utils/hash.d.ts +2 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/meta.d.ts +3 -1
- package/dist/utils/meta.d.ts.map +1 -1
- package/dist/utils/routing.d.ts +8 -1
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/ui.d.ts +13 -0
- package/dist/utils/ui.d.ts.map +1 -0
- package/package.json +5 -5
- package/src/Widget.tsx +5 -2
- package/src/components/BlockchainsSection/BlockchainsSection.tsx +2 -2
- package/src/components/TokenList/TokenList.tsx +1 -1
- package/src/constants/fonts.ts +1 -0
- package/src/hooks/useTheme.ts +44 -26
- package/src/index.ts +33 -26
- package/src/store/bestRoute.ts +12 -38
- package/src/types/config.ts +5 -10
- package/src/utils/colors.ts +93 -0
- package/src/utils/common.ts +0 -49
- package/src/utils/configs.ts +3 -0
- package/src/utils/hash.ts +27 -0
- package/src/utils/meta.ts +11 -1
- package/src/utils/routing.ts +58 -0
- package/src/utils/ui.ts +79 -0
- package/dist/constants.d.ts.map +0 -1
- /package/src/{constants.ts → constants/index.ts} +0 -0
package/src/utils/common.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
1
|
export function removeDuplicateFrom<T>(array: T[]): T[] {
|
|
3
2
|
return Array.from(new Set(array));
|
|
4
3
|
}
|
|
@@ -31,53 +30,5 @@ export function containsText(text: string, searchText: string): boolean {
|
|
|
31
30
|
return text.toLowerCase().indexOf(searchText.toLowerCase()) > -1;
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
export const colorShade = (col: string, amt: number) => {
|
|
35
|
-
col = col.replace(/^#/, '');
|
|
36
|
-
if (col.length === 3) {
|
|
37
|
-
col = col[0] + col[0] + col[1] + col[1] + col[2] + col[2];
|
|
38
|
-
}
|
|
39
|
-
let [r, g, b]: any = col.match(/.{2}/g);
|
|
40
|
-
[r, g, b] = [
|
|
41
|
-
parseInt(r, 16) + amt,
|
|
42
|
-
parseInt(g, 16) + amt,
|
|
43
|
-
parseInt(b, 16) + amt,
|
|
44
|
-
];
|
|
45
|
-
|
|
46
|
-
r = Math.max(Math.min(255, r), 0).toString(16);
|
|
47
|
-
g = Math.max(Math.min(255, g), 0).toString(16);
|
|
48
|
-
b = Math.max(Math.min(255, b), 0).toString(16);
|
|
49
|
-
|
|
50
|
-
const rr = (r.length < 2 ? '0' : '') + r;
|
|
51
|
-
const gg = (g.length < 2 ? '0' : '') + g;
|
|
52
|
-
const bb = (b.length < 2 ? '0' : '') + b;
|
|
53
|
-
|
|
54
|
-
return `#${rr}${gg}${bb}`;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export const generateRangeColors = (name: string, color: string) => {
|
|
58
|
-
let colors = { [name]: color };
|
|
59
|
-
for (let i = 1; i < 10; i++) {
|
|
60
|
-
if (i < 5) {
|
|
61
|
-
colors = {
|
|
62
|
-
...colors,
|
|
63
|
-
[name + i * 100]: colorShade(color, (5 - i) * 32),
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
if (i === 5) {
|
|
67
|
-
colors = {
|
|
68
|
-
...colors,
|
|
69
|
-
[name + i * 100]: color,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
if (i > 5) {
|
|
73
|
-
colors = {
|
|
74
|
-
...colors,
|
|
75
|
-
[name + i * 100]: colorShade(color, -((i - 5) * 32)),
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return colors;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
33
|
export const getContainer = () =>
|
|
83
34
|
document.getElementById('swap-box') as HTMLElement;
|
package/src/utils/configs.ts
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
|
+
// Original Code: https://github.com/stitchesjs/stitches/blob/canary/packages/core/src/convert/toHash.js
|
|
3
|
+
|
|
4
|
+
const toAlphabeticChar = (code: number) =>
|
|
5
|
+
String.fromCharCode(code + (code > 25 ? 39 : 97));
|
|
6
|
+
|
|
7
|
+
const toAlphabeticName = (code: number) => {
|
|
8
|
+
let name = '';
|
|
9
|
+
let x;
|
|
10
|
+
|
|
11
|
+
for (x = Math.abs(code); x > 52; x = (x / 52) | 0) {
|
|
12
|
+
name = toAlphabeticChar(x % 52) + name;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return toAlphabeticChar(x % 52) + name;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const toPhash = (h: number, x: string) => {
|
|
19
|
+
let i = x.length;
|
|
20
|
+
while (i) {
|
|
21
|
+
h = (h * 33) ^ x.charCodeAt(--i);
|
|
22
|
+
}
|
|
23
|
+
return h;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const toHash = (value: object) =>
|
|
27
|
+
toAlphabeticName(toPhash(5381, JSON.stringify(value)) >>> 0);
|
package/src/utils/meta.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { BlockchainMeta } from 'rango-sdk';
|
|
1
|
+
import type { Asset, BlockchainMeta, Token } from 'rango-sdk';
|
|
2
|
+
|
|
3
|
+
import { tokensAreEqual } from './wallets';
|
|
2
4
|
|
|
3
5
|
export function getBlockchainDisplayNameFor(
|
|
4
6
|
blockchainName: string,
|
|
@@ -14,3 +16,11 @@ export function getBlockchainShortNameFor(
|
|
|
14
16
|
return blockchains.find((blockchain) => blockchain.name === blockchainName)
|
|
15
17
|
?.shortName;
|
|
16
18
|
}
|
|
19
|
+
|
|
20
|
+
export function findToken(t: Asset, tokens: Token[]) {
|
|
21
|
+
return tokens.find((token) => tokensAreEqual(token, t)) ?? null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function findBlockchain(name: string, blockchains: BlockchainMeta[]) {
|
|
25
|
+
return blockchains.find((blockchain) => blockchain.name === name) ?? null;
|
|
26
|
+
}
|
package/src/utils/routing.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
Token,
|
|
14
14
|
} from 'rango-sdk';
|
|
15
15
|
|
|
16
|
+
import { getLastSuccessfulStep } from '@rango-dev/queue-manager-rango-preset';
|
|
16
17
|
import BigNumber from 'bignumber.js';
|
|
17
18
|
|
|
18
19
|
import {
|
|
@@ -25,6 +26,7 @@ import {
|
|
|
25
26
|
} from '../constants/routing';
|
|
26
27
|
|
|
27
28
|
import { areEqual } from './common';
|
|
29
|
+
import { findBlockchain, findToken } from './meta';
|
|
28
30
|
import { numberToString } from './numbers';
|
|
29
31
|
|
|
30
32
|
export function searchParamsToToken(
|
|
@@ -261,3 +263,59 @@ export function findCommonTokens<T extends Asset[], R extends Asset[]>(
|
|
|
261
263
|
|
|
262
264
|
return listB.filter((token) => set.has(tokenToString(token))) as R;
|
|
263
265
|
}
|
|
266
|
+
|
|
267
|
+
export function createRetryRoute(
|
|
268
|
+
pendingSwap: PendingSwap,
|
|
269
|
+
blockchains: BlockchainMeta[],
|
|
270
|
+
tokens: Token[]
|
|
271
|
+
): {
|
|
272
|
+
fromBlockchain: BlockchainMeta | null;
|
|
273
|
+
fromToken: Token | null;
|
|
274
|
+
toBlockchain: BlockchainMeta | null;
|
|
275
|
+
toToken: Token | null;
|
|
276
|
+
inputAmount: string;
|
|
277
|
+
} {
|
|
278
|
+
const firstStep = pendingSwap.steps[0];
|
|
279
|
+
const lastStep = pendingSwap.steps[pendingSwap.steps.length - 1];
|
|
280
|
+
const lastSuccessfulStep = getLastSuccessfulStep(pendingSwap.steps);
|
|
281
|
+
|
|
282
|
+
const toToken = {
|
|
283
|
+
blockchain: lastStep.toBlockchain,
|
|
284
|
+
symbol: lastStep.toSymbol,
|
|
285
|
+
address: lastStep.toSymbolAddress,
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const fromBlockchainMeta = findBlockchain(
|
|
289
|
+
lastSuccessfulStep
|
|
290
|
+
? lastSuccessfulStep.toBlockchain
|
|
291
|
+
: firstStep.fromBlockchain,
|
|
292
|
+
blockchains
|
|
293
|
+
);
|
|
294
|
+
const toBlockchainMeta = findBlockchain(lastStep.toBlockchain, blockchains);
|
|
295
|
+
const fromTokenMeta = findToken(
|
|
296
|
+
lastSuccessfulStep
|
|
297
|
+
? {
|
|
298
|
+
blockchain: fromBlockchainMeta?.name ?? '',
|
|
299
|
+
symbol: lastSuccessfulStep.toSymbol,
|
|
300
|
+
address: lastSuccessfulStep.toSymbolAddress,
|
|
301
|
+
}
|
|
302
|
+
: {
|
|
303
|
+
blockchain: fromBlockchainMeta?.name ?? '',
|
|
304
|
+
symbol: firstStep.fromSymbol,
|
|
305
|
+
address: firstStep.fromSymbolAddress,
|
|
306
|
+
},
|
|
307
|
+
tokens
|
|
308
|
+
);
|
|
309
|
+
const toTokenMeta = findToken(toToken, tokens);
|
|
310
|
+
const inputAmount = lastSuccessfulStep
|
|
311
|
+
? lastSuccessfulStep.outputAmount ?? ''
|
|
312
|
+
: pendingSwap.inputAmount;
|
|
313
|
+
|
|
314
|
+
return {
|
|
315
|
+
fromBlockchain: fromBlockchainMeta,
|
|
316
|
+
fromToken: fromTokenMeta,
|
|
317
|
+
toBlockchain: toBlockchainMeta,
|
|
318
|
+
toToken: toTokenMeta,
|
|
319
|
+
inputAmount,
|
|
320
|
+
};
|
|
321
|
+
}
|
package/src/utils/ui.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
|
+
import type { WidgetTheme } from '../types';
|
|
3
|
+
import type { createTheme } from '@rango-dev/ui';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
theme as baseThemeTokens,
|
|
7
|
+
darkColors as defaultDarkColors,
|
|
8
|
+
} from '@rango-dev/ui';
|
|
9
|
+
|
|
10
|
+
import { generateColors } from '../utils/colors';
|
|
11
|
+
import { toHash } from '../utils/hash';
|
|
12
|
+
|
|
13
|
+
import { THEME_CLASS_NAME_PREFIX } from './configs';
|
|
14
|
+
|
|
15
|
+
interface CustomizedThemeValues {
|
|
16
|
+
id: string;
|
|
17
|
+
tokens: Parameters<typeof createTheme>[0];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface CustomizedTheme {
|
|
21
|
+
light: undefined | CustomizedThemeValues;
|
|
22
|
+
dark: undefined | CustomizedThemeValues;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function customizedThemeTokens(
|
|
26
|
+
colors: WidgetTheme['colors']
|
|
27
|
+
): CustomizedTheme {
|
|
28
|
+
const baseColors = baseThemeTokens.colors;
|
|
29
|
+
|
|
30
|
+
const darkColorsWithDefaults = generateColors(
|
|
31
|
+
{
|
|
32
|
+
...baseColors,
|
|
33
|
+
...defaultDarkColors,
|
|
34
|
+
},
|
|
35
|
+
colors?.dark
|
|
36
|
+
);
|
|
37
|
+
const lightColorsWithDefaults = generateColors(baseColors, colors?.light);
|
|
38
|
+
const hasDefaultDarkColors = Object.keys(darkColorsWithDefaults).length > 0;
|
|
39
|
+
const hasDefaultLightColors = Object.keys(lightColorsWithDefaults).length > 0;
|
|
40
|
+
|
|
41
|
+
let light: CustomizedTheme['light'] = undefined;
|
|
42
|
+
let dark: CustomizedTheme['dark'] = undefined;
|
|
43
|
+
|
|
44
|
+
if (hasDefaultLightColors) {
|
|
45
|
+
const tokens = { colors: lightColorsWithDefaults };
|
|
46
|
+
const id = `${THEME_CLASS_NAME_PREFIX}-light-${toHash(tokens)}`;
|
|
47
|
+
light = {
|
|
48
|
+
id,
|
|
49
|
+
tokens,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
if (hasDefaultDarkColors) {
|
|
53
|
+
const tokens = {
|
|
54
|
+
colors: {
|
|
55
|
+
...darkColorsWithDefaults,
|
|
56
|
+
// Reverse the neutrals shade
|
|
57
|
+
neutral100: darkColorsWithDefaults.neutral900,
|
|
58
|
+
neutral200: darkColorsWithDefaults.neutral800,
|
|
59
|
+
neutral300: darkColorsWithDefaults.neutral700,
|
|
60
|
+
neutral400: darkColorsWithDefaults.neutral600,
|
|
61
|
+
neutral500: darkColorsWithDefaults.neutral500,
|
|
62
|
+
neutral600: darkColorsWithDefaults.neutral400,
|
|
63
|
+
neutral700: darkColorsWithDefaults.neutral300,
|
|
64
|
+
neutral800: darkColorsWithDefaults.neutral200,
|
|
65
|
+
neutral900: darkColorsWithDefaults.neutral100,
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
const id = `${THEME_CLASS_NAME_PREFIX}-dark-${toHash(tokens)}`;
|
|
69
|
+
dark = {
|
|
70
|
+
id,
|
|
71
|
+
tokens,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
light,
|
|
77
|
+
dark,
|
|
78
|
+
};
|
|
79
|
+
}
|
package/dist/constants.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,yCAAyC,CAAC"}
|
|
File without changes
|