@rango-dev/widget-embedded 0.14.1-next.0 → 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.
Files changed (87) hide show
  1. package/dist/Widget.d.ts.map +1 -1
  2. package/dist/components/BlockchainList/BlockchainList.styles.d.ts +8 -0
  3. package/dist/components/BlockchainList/BlockchainList.styles.d.ts.map +1 -1
  4. package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts +4 -0
  5. package/dist/components/BlockchainsSection/BlockchainsSection.styles.d.ts.map +1 -1
  6. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +60 -0
  7. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
  8. package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts +12 -0
  9. package/dist/components/ConfirmWalletsModal/WalletList.styles.d.ts.map +1 -1
  10. package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +16 -0
  11. package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
  12. package/dist/components/Layout/Layout.styles.d.ts +12 -0
  13. package/dist/components/Layout/Layout.styles.d.ts.map +1 -1
  14. package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts +4 -0
  15. package/dist/components/LoadingLiquiditySourceList/LoadingLiquiditySourceList.styles.d.ts.map +1 -1
  16. package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts +12 -0
  17. package/dist/components/LoadingSwapDetails/LoadingSwapDetails.styles.d.ts.map +1 -1
  18. package/dist/components/NoRoutes/NoRoutes.styles.d.ts +12 -0
  19. package/dist/components/NoRoutes/NoRoutes.styles.d.ts.map +1 -1
  20. package/dist/components/NotificationContent/NotificationContent.styles.d.ts +16 -0
  21. package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +1 -1
  22. package/dist/components/RouteErrors/RouteErrors.styles.d.ts +16 -0
  23. package/dist/components/RouteErrors/RouteErrors.styles.d.ts.map +1 -1
  24. package/dist/components/SearchInput/SearchInput.styles.d.ts +4 -0
  25. package/dist/components/SearchInput/SearchInput.styles.d.ts.map +1 -1
  26. package/dist/components/SettingsContainer/SettingsContainer.style.d.ts +16 -0
  27. package/dist/components/SettingsContainer/SettingsContainer.style.d.ts.map +1 -1
  28. package/dist/components/Slippage/Slippage.styles.d.ts +16 -0
  29. package/dist/components/Slippage/Slippage.styles.d.ts.map +1 -1
  30. package/dist/components/SwapDetails/SwapDetails.styles.d.ts +24 -0
  31. package/dist/components/SwapDetails/SwapDetails.styles.d.ts.map +1 -1
  32. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts +4 -0
  33. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.styles.d.ts.map +1 -1
  34. package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts +4 -0
  35. package/dist/components/SwapDetailsModal/SwapDetailsModal.styles.d.ts.map +1 -1
  36. package/dist/components/SwapsGroup/SwapsGroup.styles.d.ts +16 -0
  37. package/dist/components/SwapsGroup/SwapsGroup.styles.d.ts.map +1 -1
  38. package/dist/components/TokenList/TokenList.styles.d.ts +40 -0
  39. package/dist/components/TokenList/TokenList.styles.d.ts.map +1 -1
  40. package/dist/components/WalletModal/WalletModalContent.styles.d.ts +16 -0
  41. package/dist/components/WalletModal/WalletModalContent.styles.d.ts.map +1 -1
  42. package/dist/constants/fonts.d.ts +2 -0
  43. package/dist/constants/fonts.d.ts.map +1 -0
  44. package/dist/{constants.d.ts → constants/index.d.ts} +1 -1
  45. package/dist/constants/index.d.ts.map +1 -0
  46. package/dist/hooks/useTheme.d.ts +2 -2
  47. package/dist/hooks/useTheme.d.ts.map +1 -1
  48. package/dist/index.d.ts +9 -6
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +1 -1
  51. package/dist/index.js.map +4 -4
  52. package/dist/store/bestRoute.d.ts.map +1 -1
  53. package/dist/types/config.d.ts +5 -10
  54. package/dist/types/config.d.ts.map +1 -1
  55. package/dist/utils/colors.d.ts +11 -0
  56. package/dist/utils/colors.d.ts.map +1 -0
  57. package/dist/utils/common.d.ts +0 -4
  58. package/dist/utils/common.d.ts.map +1 -1
  59. package/dist/utils/configs.d.ts +2 -0
  60. package/dist/utils/configs.d.ts.map +1 -1
  61. package/dist/utils/hash.d.ts +2 -0
  62. package/dist/utils/hash.d.ts.map +1 -0
  63. package/dist/utils/meta.d.ts +3 -1
  64. package/dist/utils/meta.d.ts.map +1 -1
  65. package/dist/utils/routing.d.ts +8 -1
  66. package/dist/utils/routing.d.ts.map +1 -1
  67. package/dist/utils/ui.d.ts +13 -0
  68. package/dist/utils/ui.d.ts.map +1 -0
  69. package/package.json +5 -5
  70. package/src/Widget.tsx +5 -2
  71. package/src/components/BlockchainsSection/BlockchainsSection.tsx +2 -2
  72. package/src/components/TokenList/TokenList.tsx +1 -1
  73. package/src/constants/fonts.ts +1 -0
  74. package/src/hooks/useSyncStoresWithConfig.ts +1 -1
  75. package/src/hooks/useTheme.ts +44 -26
  76. package/src/index.ts +33 -26
  77. package/src/store/bestRoute.ts +24 -48
  78. package/src/types/config.ts +5 -10
  79. package/src/utils/colors.ts +93 -0
  80. package/src/utils/common.ts +0 -49
  81. package/src/utils/configs.ts +3 -0
  82. package/src/utils/hash.ts +27 -0
  83. package/src/utils/meta.ts +11 -1
  84. package/src/utils/routing.ts +58 -0
  85. package/src/utils/ui.ts +79 -0
  86. package/dist/constants.d.ts.map +0 -1
  87. /package/src/{constants.ts → constants/index.ts} +0 -0
@@ -0,0 +1,93 @@
1
+ import type { WidgetColors, WidgetColorsKeys } from '../types';
2
+
3
+ export const colorShade = (col: string, amt: number) => {
4
+ const RANGE = 255;
5
+ const COL = 3;
6
+ const RADIX = 16;
7
+
8
+ col = col.replace(/^#/, '');
9
+ if (col.length === COL) {
10
+ col = col[0] + col[0] + col[1] + col[1] + col[2] + col[2];
11
+ }
12
+ let [r, g, b]: any = col.match(/.{2}/g);
13
+ [r, g, b] = [
14
+ parseInt(r, RADIX) + amt,
15
+ parseInt(g, RADIX) + amt,
16
+ parseInt(b, RADIX) + amt,
17
+ ];
18
+
19
+ r = Math.max(Math.min(RANGE, r), 0).toString(RADIX);
20
+ g = Math.max(Math.min(RANGE, g), 0).toString(RADIX);
21
+ b = Math.max(Math.min(RANGE, b), 0).toString(RADIX);
22
+
23
+ const rr = (r.length < 2 ? '0' : '') + r;
24
+ const gg = (g.length < 2 ? '0' : '') + g;
25
+ const bb = (b.length < 2 ? '0' : '') + b;
26
+
27
+ return `#${rr}${gg}${bb}`;
28
+ };
29
+
30
+ export const generateRangeColors = (name: string, color: string) => {
31
+ const NUMBER_OF_COLORS = 10;
32
+ const HALF_NUMBER_OF_COLORS = 5;
33
+ const COLOR_SUFFIX = 100;
34
+ const AMT = 32;
35
+
36
+ let colors = { [name]: color };
37
+ for (let i = 1; i < NUMBER_OF_COLORS; i++) {
38
+ if (i < HALF_NUMBER_OF_COLORS) {
39
+ colors = {
40
+ ...colors,
41
+ [name + i * COLOR_SUFFIX]: colorShade(
42
+ color,
43
+ (HALF_NUMBER_OF_COLORS - i) * AMT
44
+ ),
45
+ };
46
+ }
47
+ if (i === HALF_NUMBER_OF_COLORS) {
48
+ colors = {
49
+ ...colors,
50
+ [name + i * COLOR_SUFFIX]: color,
51
+ };
52
+ }
53
+ if (i > HALF_NUMBER_OF_COLORS) {
54
+ colors = {
55
+ ...colors,
56
+ [name + i * COLOR_SUFFIX]: colorShade(
57
+ color,
58
+ -((i - HALF_NUMBER_OF_COLORS) * AMT)
59
+ ),
60
+ };
61
+ }
62
+ }
63
+ return colors;
64
+ };
65
+ export const generateColors = (
66
+ mainColors: { [x: string]: string },
67
+ colors?: WidgetColors
68
+ ) => {
69
+ if (!colors || !Object.entries(colors).length) {
70
+ return {};
71
+ }
72
+ let changeColors = false;
73
+ let listOfColors = { ...mainColors };
74
+ for (const colorKey in colors) {
75
+ const color = colors[colorKey as WidgetColorsKeys];
76
+
77
+ if (!!color && color !== mainColors[colorKey]) {
78
+ changeColors = true;
79
+ if (colorKey === 'background' || colorKey === 'foreground') {
80
+ listOfColors = {
81
+ ...listOfColors,
82
+ [colorKey]: color,
83
+ };
84
+ } else {
85
+ listOfColors = {
86
+ ...listOfColors,
87
+ ...generateRangeColors(colorKey, color),
88
+ };
89
+ }
90
+ }
91
+ }
92
+ return changeColors ? listOfColors : {};
93
+ };
@@ -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;
@@ -34,3 +34,6 @@ export function initConfig(nextConfigs: Configs) {
34
34
 
35
35
  export const DEFAULT_PRIMARY_RADIUS = 20;
36
36
  export const DEFAULT_SECONDARY_RADIUS = 25;
37
+ export const DEFAULT_FONT_FAMILY = 'Roboto';
38
+
39
+ export const THEME_CLASS_NAME_PREFIX = `theme-widget`;
@@ -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
+ }
@@ -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
+ }
@@ -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
+ }
@@ -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