@rango-dev/widget-embedded 0.37.0 → 0.37.1-next.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 (157) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/QueueManager.d.ts.map +1 -1
  3. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
  4. package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
  5. package/dist/components/Layout/Layout.d.ts.map +1 -1
  6. package/dist/components/Quote/Quote.d.ts.map +1 -1
  7. package/dist/components/Quote/Quote.styles.d.ts +1 -1
  8. package/dist/components/Quote/Quote.types.d.ts +2 -0
  9. package/dist/components/Quote/Quote.types.d.ts.map +1 -1
  10. package/dist/components/Quote/QuoteCostDetails.d.ts.map +1 -1
  11. package/dist/components/Quote/QuoteCostDetails.styles.d.ts.map +1 -1
  12. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts.map +1 -1
  13. package/dist/components/Quotes/Quotes.d.ts.map +1 -1
  14. package/dist/components/RefreshModal/RefreshModal.styles.d.ts +1 -1
  15. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  16. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts +1 -1
  17. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts.map +1 -1
  18. package/dist/components/SwapDetailsModal/SwapDetailsCompleteModal.d.ts.map +1 -1
  19. package/dist/components/TokenList/TokenList.d.ts.map +1 -1
  20. package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts +2 -1
  21. package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts.map +1 -1
  22. package/dist/components/WalletStatefulConnect/Namespaces.d.ts.map +1 -1
  23. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts +1 -1
  24. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts.map +1 -1
  25. package/dist/constants/quote.d.ts +10 -0
  26. package/dist/constants/quote.d.ts.map +1 -1
  27. package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts.map +1 -1
  28. package/dist/containers/Inputs/Inputs.d.ts.map +1 -1
  29. package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -1
  30. package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
  31. package/dist/containers/WidgetInfo/WidgetInfo.d.ts.map +1 -1
  32. package/dist/containers/WidgetInfo/WidgetInfo.helpers.d.ts +1 -1
  33. package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts +3 -3
  34. package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts.map +1 -1
  35. package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -1
  36. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +6 -4
  37. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -1
  38. package/dist/hooks/useFetchApiConfig.d.ts.map +1 -1
  39. package/dist/hooks/useFetchCustomToken.d.ts.map +1 -1
  40. package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts +2 -1
  41. package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
  42. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts +3 -5
  43. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts.map +1 -1
  44. package/dist/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.d.ts.map +1 -1
  45. package/dist/hooks/useSwapInput.d.ts.map +1 -1
  46. package/dist/hooks/useWalletList.d.ts.map +1 -1
  47. package/dist/hooks/useWalletProviders/useWalletProviders.d.ts +2 -3
  48. package/dist/hooks/useWalletProviders/useWalletProviders.d.ts.map +1 -1
  49. package/dist/index.d.ts +1 -1
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +2 -2
  52. package/dist/index.js.map +4 -4
  53. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  54. package/dist/pages/Home.d.ts.map +1 -1
  55. package/dist/pages/SelectSwapItemsPage.d.ts.map +1 -1
  56. package/dist/store/app.d.ts +2 -4
  57. package/dist/store/app.d.ts.map +1 -1
  58. package/dist/store/quote.d.ts.map +1 -1
  59. package/dist/store/slices/config.d.ts +4 -0
  60. package/dist/store/slices/config.d.ts.map +1 -1
  61. package/dist/store/slices/data.d.ts.map +1 -1
  62. package/dist/store/slices/types.d.ts +6 -0
  63. package/dist/store/slices/types.d.ts.map +1 -0
  64. package/dist/store/slices/wallets.d.ts +80 -0
  65. package/dist/store/slices/wallets.d.ts.map +1 -0
  66. package/dist/store/ui.d.ts +4 -0
  67. package/dist/store/ui.d.ts.map +1 -1
  68. package/dist/store/utils/wallets.d.ts +17 -0
  69. package/dist/store/utils/wallets.d.ts.map +1 -0
  70. package/dist/types/config.d.ts +6 -3
  71. package/dist/types/config.d.ts.map +1 -1
  72. package/dist/types/quote.d.ts +8 -17
  73. package/dist/types/quote.d.ts.map +1 -1
  74. package/dist/types/wallets.d.ts +3 -7
  75. package/dist/types/wallets.d.ts.map +1 -1
  76. package/dist/utils/providers.d.ts +8 -9
  77. package/dist/utils/providers.d.ts.map +1 -1
  78. package/dist/utils/quote.d.ts +5 -6
  79. package/dist/utils/quote.d.ts.map +1 -1
  80. package/dist/utils/settings.d.ts +1 -0
  81. package/dist/utils/settings.d.ts.map +1 -1
  82. package/dist/utils/swap.d.ts +5 -5
  83. package/dist/utils/swap.d.ts.map +1 -1
  84. package/dist/utils/wallets.d.ts +12 -14
  85. package/dist/utils/wallets.d.ts.map +1 -1
  86. package/dist/widget-embedded.build.json +1 -1
  87. package/package.json +9 -9
  88. package/src/QueueManager.tsx +17 -11
  89. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +5 -24
  90. package/src/components/ConfirmWalletsModal/WalletList.tsx +10 -7
  91. package/src/components/Layout/Layout.tsx +1 -3
  92. package/src/components/Quote/Quote.tsx +22 -3
  93. package/src/components/Quote/Quote.types.ts +2 -0
  94. package/src/components/Quote/QuoteCostDetails.styles.ts +0 -1
  95. package/src/components/Quote/QuoteCostDetails.tsx +23 -4
  96. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +42 -22
  97. package/src/components/Quotes/Quotes.tsx +2 -3
  98. package/src/components/StatefulConnectModal/StatefulConnectModal.tsx +1 -1
  99. package/src/components/SwapDetails/SwapDetails.tsx +14 -6
  100. package/src/components/SwapDetailsAlerts/SwapDetailsAlerts.types.ts +1 -1
  101. package/src/components/SwapDetailsModal/SwapDetailsCompleteModal.tsx +26 -13
  102. package/src/components/TokenList/TokenList.tsx +4 -27
  103. package/src/components/WalletStatefulConnect/DerivationPath.helpers.ts +2 -1
  104. package/src/components/WalletStatefulConnect/Namespaces.tsx +31 -38
  105. package/src/components/WalletStatefulConnect/Namespaces.types.tsx +1 -1
  106. package/src/constants/quote.ts +25 -0
  107. package/src/containers/ExpandedQuotes/ExpandedQuotes.styles.ts +1 -0
  108. package/src/containers/ExpandedQuotes/ExpandedQuotes.tsx +1 -1
  109. package/src/containers/Inputs/Inputs.tsx +20 -7
  110. package/src/containers/QuoteInfo/QuoteInfo.tsx +3 -9
  111. package/src/containers/Wallets/Wallets.tsx +82 -16
  112. package/src/containers/WidgetInfo/WidgetInfo.helpers.ts +2 -2
  113. package/src/containers/WidgetInfo/WidgetInfo.tsx +10 -8
  114. package/src/containers/WidgetInfo/WidgetInfo.types.ts +3 -3
  115. package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +29 -66
  116. package/src/hooks/useConfirmSwap/useConfirmSwap.ts +10 -15
  117. package/src/hooks/useFetchApiConfig.ts +5 -1
  118. package/src/hooks/useFetchCustomToken.ts +5 -0
  119. package/src/hooks/useStatefulConnect/useStatefulConnect.ts +50 -17
  120. package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +3 -5
  121. package/src/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.ts +7 -6
  122. package/src/hooks/useSwapInput.ts +3 -11
  123. package/src/hooks/useWalletList.ts +6 -8
  124. package/src/hooks/useWalletProviders/useWalletProviders.ts +8 -12
  125. package/src/index.ts +1 -1
  126. package/src/pages/ConfirmSwapPage.tsx +7 -15
  127. package/src/pages/Home.tsx +5 -3
  128. package/src/pages/SelectSwapItemsPage.tsx +1 -2
  129. package/src/store/app.ts +4 -4
  130. package/src/store/quote.ts +3 -13
  131. package/src/store/slices/config.ts +76 -0
  132. package/src/store/slices/data.test.ts +23 -1
  133. package/src/store/slices/data.ts +3 -2
  134. package/src/store/slices/types.ts +9 -0
  135. package/src/store/slices/wallets.ts +577 -0
  136. package/src/store/ui.ts +6 -0
  137. package/src/store/utils/wallets.ts +111 -0
  138. package/src/types/config.ts +7 -3
  139. package/src/types/quote.ts +10 -24
  140. package/src/types/wallets.ts +3 -7
  141. package/src/utils/providers.ts +88 -36
  142. package/src/utils/quote.ts +57 -45
  143. package/src/utils/settings.ts +4 -0
  144. package/src/utils/swap.ts +56 -37
  145. package/src/utils/wallets.ts +76 -141
  146. package/dist/constants/warnings.d.ts +0 -3
  147. package/dist/constants/warnings.d.ts.map +0 -1
  148. package/dist/hooks/useObserveBalanceChanges/index.d.ts +0 -2
  149. package/dist/hooks/useObserveBalanceChanges/index.d.ts.map +0 -1
  150. package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts +0 -4
  151. package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts.map +0 -1
  152. package/dist/store/wallets.d.ts +0 -66
  153. package/dist/store/wallets.d.ts.map +0 -1
  154. package/src/constants/warnings.ts +0 -26
  155. package/src/hooks/useObserveBalanceChanges/index.ts +0 -1
  156. package/src/hooks/useObserveBalanceChanges/useObserveBalanceChanges.ts +0 -68
  157. package/src/store/wallets.ts +0 -268
@@ -21,11 +21,7 @@ import {
21
21
  WidgetEvents,
22
22
  } from '../types';
23
23
  import { isPositiveNumber } from '../utils/numbers';
24
- import {
25
- getQuoteFromTokenUsdPrice,
26
- getQuoteToTokenUsdPrice,
27
- } from '../utils/quote';
28
- import { calcOutputUsdValue } from '../utils/swap';
24
+ import { getUsdInputFrom, getUsdOutputFrom } from '../utils/swap';
29
25
 
30
26
  import createSelectors from './selectors';
31
27
 
@@ -137,14 +133,8 @@ export const useQuoteStore = createSelectors(
137
133
  outputAmount = !!quote?.outputAmount
138
134
  ? new BigNumber(quote?.outputAmount)
139
135
  : null;
140
- inputUsdValue = calcOutputUsdValue(
141
- state.inputAmount,
142
- getQuoteFromTokenUsdPrice(quote) || state.fromToken?.usdPrice
143
- );
144
- outputUsdValue = calcOutputUsdValue(
145
- quote.outputAmount,
146
- getQuoteToTokenUsdPrice(quote) || state.toToken?.usdPrice
147
- );
136
+ inputUsdValue = getUsdInputFrom(quote) ?? ZERO;
137
+ outputUsdValue = getUsdOutputFrom(quote) ?? ZERO;
148
138
  }
149
139
  return {
150
140
  selectedQuote: quote,
@@ -3,9 +3,31 @@ import type { SettingsSlice } from './settings';
3
3
  import type { WidgetConfig } from '../../types';
4
4
  import type { StateCreatorWithInitialData } from '../app';
5
5
 
6
+ import { allProviders as getAllProviders } from '@rango-dev/provider-all';
7
+ import { type VersionedProviders } from '@rango-dev/wallets-core';
8
+
6
9
  import { cacheService } from '../../services/cacheService';
10
+ import {
11
+ matchAndGenerateProviders,
12
+ type ProvidersOptions,
13
+ } from '../../utils/providers';
7
14
  import { matchTokensFromConfigWithMeta } from '../utils';
8
15
 
16
+ function makeProvidersOptionsFromConfig(
17
+ config: WidgetConfig
18
+ ): ProvidersOptions {
19
+ const options: ProvidersOptions = {
20
+ walletConnectProjectId: config?.walletConnectProjectId,
21
+ trezorManifest: config?.trezorManifest,
22
+ tonConnect: config?.tonConnect,
23
+ walletConnectListedDesktopWalletLink:
24
+ config.__UNSTABLE_OR_INTERNAL__?.walletConnectListedDesktopWalletLink,
25
+ experimentalWallet: config.features?.experimentalWallet,
26
+ };
27
+
28
+ return options;
29
+ }
30
+
9
31
  export const DEFAULT_CONFIG: WidgetConfig = {
10
32
  apiKey: '',
11
33
  title: undefined,
@@ -21,6 +43,9 @@ export const DEFAULT_CONFIG: WidgetConfig = {
21
43
  manifestUrl:
22
44
  'https://raw.githubusercontent.com/rango-exchange/rango-types/main/assets/manifests/tonconnect-manifest.json',
23
45
  },
46
+ features: {
47
+ experimentalWallet: 'enabled',
48
+ },
24
49
  };
25
50
 
26
51
  interface IframeConfigs {
@@ -58,6 +83,31 @@ export interface ConfigSlice {
58
83
  name: K,
59
84
  value: IframeConfigs[K]
60
85
  ) => void;
86
+ allProviders: VersionedProviders[];
87
+ buildAndSetProviders: () => void;
88
+ getAvailableProviders: () => VersionedProviders[];
89
+ }
90
+
91
+ function generateProviders(config: WidgetConfig) {
92
+ const options = makeProvidersOptionsFromConfig(config);
93
+ const envs = {
94
+ walletconnect2: {
95
+ WC_PROJECT_ID: options?.walletConnectProjectId || '',
96
+ DISABLE_MODAL_AND_OPEN_LINK:
97
+ options?.walletConnectListedDesktopWalletLink,
98
+ },
99
+ selectedProviders: config.wallets,
100
+ trezor: options?.trezorManifest
101
+ ? { manifest: options.trezorManifest }
102
+ : undefined,
103
+ tonConnect: options?.tonConnect?.manifestUrl
104
+ ? { manifestUrl: options?.tonConnect.manifestUrl }
105
+ : undefined,
106
+ };
107
+ const allProviders = getAllProviders(envs);
108
+ const allBuiltProviders = allProviders.map((build) => build());
109
+
110
+ return allBuiltProviders;
61
111
  }
62
112
 
63
113
  export const createConfigSlice: StateCreatorWithInitialData<
@@ -65,10 +115,15 @@ export const createConfigSlice: StateCreatorWithInitialData<
65
115
  ConfigSlice & SettingsSlice & DataSlice,
66
116
  ConfigSlice
67
117
  > = (initialData, set, get) => {
118
+ const allBuiltProviders = generateProviders({
119
+ ...DEFAULT_CONFIG,
120
+ ...initialData,
121
+ });
68
122
  return {
69
123
  config: { ...DEFAULT_CONFIG, ...initialData },
70
124
  iframe: DEFAULT_IFRAME_CONFIGS,
71
125
  campaignMode: DEFAULT_CAMPAIGN_MODE,
126
+ allProviders: allBuiltProviders,
72
127
  getLiquiditySources: () => {
73
128
  const { config, campaignMode } = get();
74
129
  return campaignMode.liquiditySources?.length
@@ -159,5 +214,26 @@ export const createConfigSlice: StateCreatorWithInitialData<
159
214
  },
160
215
  });
161
216
  },
217
+
218
+ buildAndSetProviders: () => {
219
+ const { config } = get();
220
+ const allBuiltProviders = generateProviders(config);
221
+
222
+ set({
223
+ allProviders: allBuiltProviders,
224
+ });
225
+ },
226
+
227
+ getAvailableProviders: () => {
228
+ const { allProviders, config } = get();
229
+ const options = makeProvidersOptionsFromConfig(config);
230
+
231
+ const availableProviders = matchAndGenerateProviders({
232
+ allProviders,
233
+ configWallets: config.wallets,
234
+ options,
235
+ });
236
+ return availableProviders;
237
+ },
162
238
  };
163
239
  };
@@ -1,3 +1,4 @@
1
+ import type { WidgetConfig } from '../../types';
1
2
  import type { AppStoreState } from '../app';
2
3
  import type { EvmBlockchainMeta, Token } from 'rango-sdk';
3
4
 
@@ -17,6 +18,27 @@ let appStoreState: AppStoreState;
17
18
  let customTokens: [Token, Token, Token];
18
19
  let rangoBlockchain: EvmBlockchainMeta;
19
20
 
21
+ const DEFAULT_CONFIG: WidgetConfig = {
22
+ apiKey: '',
23
+ walletConnectProjectId: 'e24844c5deb5193c1c14840a7af6a40b',
24
+ title: undefined,
25
+ multiWallets: true,
26
+ excludeLiquiditySources: true,
27
+ customDestination: true,
28
+ variant: 'default',
29
+ trezorManifest: {
30
+ appUrl: 'https://widget.rango.exchange/',
31
+ email: 'hi+trezorwidget@rango.exchange',
32
+ },
33
+ tonConnect: {
34
+ manifestUrl:
35
+ 'https://raw.githubusercontent.com/rango-exchange/rango-types/main/assets/manifests/tonconnect-manifest.json',
36
+ },
37
+ features: {
38
+ experimentalWallet: 'enabled',
39
+ },
40
+ };
41
+
20
42
  beforeEach(() => {
21
43
  cacheService.clear();
22
44
  rangoBlockchain = createEvmBlockchain();
@@ -60,7 +82,7 @@ beforeEach(() => {
60
82
  initData._tokensMapByBlockchainName[token.blockchain].push(tokenHash);
61
83
  });
62
84
 
63
- const appStore = createAppStore();
85
+ const appStore = createAppStore(DEFAULT_CONFIG);
64
86
  appStore.setState(initData);
65
87
  appStoreState = appStore.getState();
66
88
  });
@@ -348,8 +348,9 @@ export const createDataSlice: StateCreator<
348
348
  {};
349
349
  const tokens: Token[] = [];
350
350
  const popularTokens: Token[] = response.popularTokens;
351
- const swappers: SwapperMeta[] = response.swappers;
352
-
351
+ const swappers: SwapperMeta[] = response.swappers.filter(
352
+ (swapper) => swapper.enabled
353
+ );
353
354
  const blockchainsWithAtLeastOneToken = new Set();
354
355
 
355
356
  response.tokens.forEach((token) => {
@@ -0,0 +1,9 @@
1
+ import type { ConfigSlice } from './config';
2
+ import type { DataSlice } from './data';
3
+ import type { SettingsSlice } from './settings';
4
+ import type { WalletsSlice } from './wallets';
5
+
6
+ export type AppStoreState = DataSlice &
7
+ ConfigSlice &
8
+ SettingsSlice &
9
+ WalletsSlice;