@rango-dev/widget-embedded 0.39.0 → 0.39.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 (158) 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/StatefulConnectModal/StatefulConnectModal.d.ts +1 -2
  16. package/dist/components/StatefulConnectModal/StatefulConnectModal.d.ts.map +1 -1
  17. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  18. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts +1 -1
  19. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts.map +1 -1
  20. package/dist/components/SwapDetailsModal/SwapDetailsCompleteModal.d.ts.map +1 -1
  21. package/dist/components/TokenList/TokenList.d.ts.map +1 -1
  22. package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts +2 -1
  23. package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts.map +1 -1
  24. package/dist/components/WalletStatefulConnect/Namespaces.d.ts.map +1 -1
  25. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts +1 -1
  26. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts.map +1 -1
  27. package/dist/constants/quote.d.ts +10 -0
  28. package/dist/constants/quote.d.ts.map +1 -1
  29. package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts.map +1 -1
  30. package/dist/containers/Inputs/Inputs.d.ts.map +1 -1
  31. package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -1
  32. package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
  33. package/dist/containers/WidgetInfo/WidgetInfo.d.ts.map +1 -1
  34. package/dist/containers/WidgetInfo/WidgetInfo.helpers.d.ts +1 -1
  35. package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts +3 -3
  36. package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts.map +1 -1
  37. package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -1
  38. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +6 -4
  39. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -1
  40. package/dist/hooks/useFetchApiConfig.d.ts.map +1 -1
  41. package/dist/hooks/useFetchCustomToken.d.ts.map +1 -1
  42. package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts +2 -1
  43. package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
  44. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts +3 -5
  45. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts.map +1 -1
  46. package/dist/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.d.ts.map +1 -1
  47. package/dist/hooks/useSwapInput.d.ts.map +1 -1
  48. package/dist/hooks/useWalletList.d.ts.map +1 -1
  49. package/dist/hooks/useWalletProviders/useWalletProviders.d.ts +2 -3
  50. package/dist/hooks/useWalletProviders/useWalletProviders.d.ts.map +1 -1
  51. package/dist/index.d.ts +1 -1
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +2 -2
  54. package/dist/index.js.map +4 -4
  55. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  56. package/dist/pages/Home.d.ts.map +1 -1
  57. package/dist/pages/SelectSwapItemsPage.d.ts.map +1 -1
  58. package/dist/store/AppStore.d.ts.map +1 -1
  59. package/dist/store/app.d.ts +2 -4
  60. package/dist/store/app.d.ts.map +1 -1
  61. package/dist/store/quote.d.ts.map +1 -1
  62. package/dist/store/slices/config.d.ts +4 -0
  63. package/dist/store/slices/config.d.ts.map +1 -1
  64. package/dist/store/slices/data.d.ts.map +1 -1
  65. package/dist/store/slices/types.d.ts +6 -0
  66. package/dist/store/slices/types.d.ts.map +1 -0
  67. package/dist/store/slices/wallets.d.ts +80 -0
  68. package/dist/store/slices/wallets.d.ts.map +1 -0
  69. package/dist/store/ui.d.ts +4 -0
  70. package/dist/store/ui.d.ts.map +1 -1
  71. package/dist/store/utils/wallets.d.ts +17 -0
  72. package/dist/store/utils/wallets.d.ts.map +1 -0
  73. package/dist/types/config.d.ts +2 -2
  74. package/dist/types/config.d.ts.map +1 -1
  75. package/dist/types/quote.d.ts +8 -17
  76. package/dist/types/quote.d.ts.map +1 -1
  77. package/dist/types/wallets.d.ts +3 -7
  78. package/dist/types/wallets.d.ts.map +1 -1
  79. package/dist/utils/providers.d.ts +7 -9
  80. package/dist/utils/providers.d.ts.map +1 -1
  81. package/dist/utils/quote.d.ts +5 -6
  82. package/dist/utils/quote.d.ts.map +1 -1
  83. package/dist/utils/swap.d.ts +5 -5
  84. package/dist/utils/swap.d.ts.map +1 -1
  85. package/dist/utils/wallets.d.ts +12 -14
  86. package/dist/utils/wallets.d.ts.map +1 -1
  87. package/dist/widget-embedded.build.json +1 -1
  88. package/package.json +12 -12
  89. package/src/QueueManager.tsx +17 -11
  90. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +5 -24
  91. package/src/components/ConfirmWalletsModal/WalletList.tsx +13 -13
  92. package/src/components/Layout/Layout.tsx +1 -3
  93. package/src/components/Quote/Quote.tsx +22 -3
  94. package/src/components/Quote/Quote.types.ts +2 -0
  95. package/src/components/Quote/QuoteCostDetails.styles.ts +0 -1
  96. package/src/components/Quote/QuoteCostDetails.tsx +23 -4
  97. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +42 -22
  98. package/src/components/Quotes/Quotes.tsx +2 -3
  99. package/src/components/StatefulConnectModal/StatefulConnectModal.tsx +40 -37
  100. package/src/components/SwapDetails/SwapDetails.tsx +14 -6
  101. package/src/components/SwapDetailsAlerts/SwapDetailsAlerts.types.ts +1 -1
  102. package/src/components/SwapDetailsModal/SwapDetailsCompleteModal.tsx +26 -13
  103. package/src/components/TokenList/TokenList.tsx +4 -27
  104. package/src/components/WalletStatefulConnect/DerivationPath.helpers.ts +2 -1
  105. package/src/components/WalletStatefulConnect/Namespaces.tsx +31 -38
  106. package/src/components/WalletStatefulConnect/Namespaces.types.tsx +1 -1
  107. package/src/constants/quote.ts +25 -0
  108. package/src/containers/ExpandedQuotes/ExpandedQuotes.styles.ts +1 -0
  109. package/src/containers/ExpandedQuotes/ExpandedQuotes.tsx +1 -1
  110. package/src/containers/Inputs/Inputs.tsx +20 -7
  111. package/src/containers/QuoteInfo/QuoteInfo.tsx +3 -9
  112. package/src/containers/Wallets/Wallets.tsx +76 -16
  113. package/src/containers/WidgetInfo/WidgetInfo.helpers.ts +2 -2
  114. package/src/containers/WidgetInfo/WidgetInfo.tsx +10 -8
  115. package/src/containers/WidgetInfo/WidgetInfo.types.ts +3 -3
  116. package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +29 -66
  117. package/src/hooks/useConfirmSwap/useConfirmSwap.ts +10 -15
  118. package/src/hooks/useFetchApiConfig.ts +5 -1
  119. package/src/hooks/useFetchCustomToken.ts +5 -0
  120. package/src/hooks/useStatefulConnect/useStatefulConnect.ts +50 -17
  121. package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +3 -5
  122. package/src/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.ts +7 -6
  123. package/src/hooks/useSwapInput.ts +3 -11
  124. package/src/hooks/useWalletList.ts +4 -13
  125. package/src/hooks/useWalletProviders/useWalletProviders.ts +8 -12
  126. package/src/index.ts +1 -1
  127. package/src/pages/ConfirmSwapPage.tsx +7 -15
  128. package/src/pages/Home.tsx +5 -3
  129. package/src/pages/SelectSwapItemsPage.tsx +1 -2
  130. package/src/store/AppStore.tsx +5 -0
  131. package/src/store/app.ts +4 -4
  132. package/src/store/quote.ts +3 -13
  133. package/src/store/slices/config.ts +72 -0
  134. package/src/store/slices/data.test.ts +20 -1
  135. package/src/store/slices/data.ts +3 -2
  136. package/src/store/slices/types.ts +9 -0
  137. package/src/store/slices/wallets.ts +577 -0
  138. package/src/store/ui.ts +6 -0
  139. package/src/store/utils/wallets.ts +111 -0
  140. package/src/types/config.ts +2 -2
  141. package/src/types/quote.ts +10 -24
  142. package/src/types/wallets.ts +3 -7
  143. package/src/utils/providers.ts +78 -37
  144. package/src/utils/quote.ts +57 -45
  145. package/src/utils/swap.ts +56 -37
  146. package/src/utils/wallets.ts +81 -141
  147. package/dist/constants/warnings.d.ts +0 -3
  148. package/dist/constants/warnings.d.ts.map +0 -1
  149. package/dist/hooks/useObserveBalanceChanges/index.d.ts +0 -2
  150. package/dist/hooks/useObserveBalanceChanges/index.d.ts.map +0 -1
  151. package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts +0 -4
  152. package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts.map +0 -1
  153. package/dist/store/wallets.d.ts +0 -66
  154. package/dist/store/wallets.d.ts.map +0 -1
  155. package/src/constants/warnings.ts +0 -26
  156. package/src/hooks/useObserveBalanceChanges/index.ts +0 -1
  157. package/src/hooks/useObserveBalanceChanges/useObserveBalanceChanges.ts +0 -68
  158. package/src/store/wallets.ts +0 -268
package/src/store/app.ts CHANGED
@@ -1,6 +1,4 @@
1
- import type { ConfigSlice } from './slices/config';
2
- import type { DataSlice } from './slices/data';
3
- import type { SettingsSlice } from './slices/settings';
1
+ import type { AppStoreState } from './slices/types';
4
2
  import type { WidgetConfig } from '../types';
5
3
  import type { StateCreator } from 'zustand';
6
4
 
@@ -10,6 +8,7 @@ import { persist } from 'zustand/middleware';
10
8
  import { createConfigSlice } from './slices/config';
11
9
  import { createDataSlice } from './slices/data';
12
10
  import { createSettingsSlice } from './slices/settings';
11
+ import { createWalletsSlice } from './slices/wallets';
13
12
 
14
13
  export type StateCreatorWithInitialData<
15
14
  T extends Partial<WidgetConfig>,
@@ -20,12 +19,13 @@ export type StateCreatorWithInitialData<
20
19
  ...rest: Parameters<StateCreator<R, [], [], V>>
21
20
  ) => ReturnType<StateCreator<R, [], [], V>>;
22
21
 
23
- export type AppStoreState = DataSlice & ConfigSlice & SettingsSlice;
22
+ export type { AppStoreState };
24
23
 
25
24
  export function createAppStore(initialData?: WidgetConfig) {
26
25
  return create<AppStoreState>()(
27
26
  persist(
28
27
  (...a) => ({
28
+ ...createWalletsSlice(...a),
29
29
  ...createDataSlice(...a),
30
30
  ...createSettingsSlice(...a),
31
31
  ...createConfigSlice(initialData, ...a),
@@ -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,30 @@ 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
+ };
26
+
27
+ return options;
28
+ }
29
+
9
30
  export const DEFAULT_CONFIG: WidgetConfig = {
10
31
  apiKey: '',
11
32
  title: undefined,
@@ -58,6 +79,31 @@ export interface ConfigSlice {
58
79
  name: K,
59
80
  value: IframeConfigs[K]
60
81
  ) => void;
82
+ allProviders: VersionedProviders[];
83
+ buildAndSetProviders: () => void;
84
+ getAvailableProviders: () => VersionedProviders[];
85
+ }
86
+
87
+ function generateProviders(config: WidgetConfig) {
88
+ const options = makeProvidersOptionsFromConfig(config);
89
+ const envs = {
90
+ walletconnect2: {
91
+ WC_PROJECT_ID: options?.walletConnectProjectId || '',
92
+ DISABLE_MODAL_AND_OPEN_LINK:
93
+ options?.walletConnectListedDesktopWalletLink,
94
+ },
95
+ selectedProviders: config.wallets,
96
+ trezor: options?.trezorManifest
97
+ ? { manifest: options.trezorManifest }
98
+ : undefined,
99
+ tonConnect: options?.tonConnect?.manifestUrl
100
+ ? { manifestUrl: options?.tonConnect.manifestUrl }
101
+ : undefined,
102
+ };
103
+ const allProviders = getAllProviders(envs);
104
+ const allBuiltProviders = allProviders.map((build) => build());
105
+
106
+ return allBuiltProviders;
61
107
  }
62
108
 
63
109
  export const createConfigSlice: StateCreatorWithInitialData<
@@ -65,10 +111,15 @@ export const createConfigSlice: StateCreatorWithInitialData<
65
111
  ConfigSlice & SettingsSlice & DataSlice,
66
112
  ConfigSlice
67
113
  > = (initialData, set, get) => {
114
+ const allBuiltProviders = generateProviders({
115
+ ...DEFAULT_CONFIG,
116
+ ...initialData,
117
+ });
68
118
  return {
69
119
  config: { ...DEFAULT_CONFIG, ...initialData },
70
120
  iframe: DEFAULT_IFRAME_CONFIGS,
71
121
  campaignMode: DEFAULT_CAMPAIGN_MODE,
122
+ allProviders: allBuiltProviders,
72
123
  getLiquiditySources: () => {
73
124
  const { config, campaignMode } = get();
74
125
  return campaignMode.liquiditySources?.length
@@ -159,5 +210,26 @@ export const createConfigSlice: StateCreatorWithInitialData<
159
210
  },
160
211
  });
161
212
  },
213
+
214
+ buildAndSetProviders: () => {
215
+ const { config } = get();
216
+ const allBuiltProviders = generateProviders(config);
217
+
218
+ set({
219
+ allProviders: allBuiltProviders,
220
+ });
221
+ },
222
+
223
+ getAvailableProviders: () => {
224
+ const { allProviders, config } = get();
225
+ const options = makeProvidersOptionsFromConfig(config);
226
+
227
+ const availableProviders = matchAndGenerateProviders({
228
+ allProviders,
229
+ configWallets: config.wallets,
230
+ options,
231
+ });
232
+ return availableProviders;
233
+ },
162
234
  };
163
235
  };
@@ -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,24 @@ 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
+ };
38
+
20
39
  beforeEach(() => {
21
40
  cacheService.clear();
22
41
  rangoBlockchain = createEvmBlockchain();
@@ -60,7 +79,7 @@ beforeEach(() => {
60
79
  initData._tokensMapByBlockchainName[token.blockchain].push(tokenHash);
61
80
  });
62
81
 
63
- const appStore = createAppStore();
82
+ const appStore = createAppStore(DEFAULT_CONFIG);
64
83
  appStore.setState(initData);
65
84
  appStoreState = appStore.getState();
66
85
  });
@@ -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;