@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
@@ -7,27 +7,18 @@ import type {
7
7
  SelectedQuote,
8
8
  Wallet,
9
9
  } from '../../types';
10
- import type { BlockchainMeta, SwapResult, Token } from 'rango-sdk';
10
+ import type BigNumber from 'bignumber.js';
11
+ import type { BlockchainMeta, SwapResult } from 'rango-sdk';
11
12
 
12
13
  import { errorMessages } from '../../constants/errors';
13
- import { QuoteErrorType, QuoteUpdateType } from '../../types';
14
- import { numberToString } from '../../utils/numbers';
15
- import {
16
- generateQuoteWarnings,
17
- getPriceImpact,
18
- isNumberOfSwapsChanged,
19
- isQuoteChanged,
20
- isQuoteInternalCoinsUpdated,
21
- isQuoteSwappersUpdated,
22
- } from '../../utils/quote';
14
+ import { QuoteErrorType } from '../../types';
15
+ import { generateQuoteWarnings } from '../../utils/quote';
23
16
  import {
24
17
  checkSlippageErrors,
25
18
  generateBalanceWarnings,
26
19
  getLimitErrorMessage,
27
20
  getMinRequiredSlippage,
28
- getQuoteOutputAmount,
29
21
  hasLimitError,
30
- isOutputAmountChangedALot,
31
22
  } from '../../utils/swap';
32
23
 
33
24
  /**
@@ -82,72 +73,44 @@ export function getQuoteError(swaps: SwapResult[]): QuoteErrorResponse | null {
82
73
  return null;
83
74
  }
84
75
 
85
- export function generateWarnings(
86
- previousQuote: SelectedQuote | undefined,
87
- currentQuote: SelectedQuote,
88
- params: {
89
- fromToken: Token;
90
- toToken: Token;
91
- meta: { blockchains: BlockchainMeta[] };
92
- selectedWallets: Wallet[];
93
- userSlippage: number;
94
- findToken: FindToken;
95
- }
96
- ): ConfirmSwapWarnings {
97
- let quoteChanged = false;
98
- if (previousQuote) {
99
- quoteChanged = isQuoteChanged(previousQuote, currentQuote);
100
- }
76
+ export function generateWarnings(params: {
77
+ currentQuote: SelectedQuote;
78
+ previousQuote?: SelectedQuote;
79
+ meta: { blockchains: BlockchainMeta[] };
80
+ selectedWallets: Wallet[];
81
+ userSlippage: number;
82
+ inputUsdValue: BigNumber | null;
83
+ findToken: FindToken;
84
+ }): ConfirmSwapWarnings {
85
+ const {
86
+ currentQuote,
87
+ previousQuote,
88
+ meta,
89
+ selectedWallets,
90
+ userSlippage,
91
+ findToken,
92
+ } = params;
93
+
101
94
  const output: ConfirmSwapWarnings = {
102
95
  quote: null,
103
- quoteUpdate: null,
104
96
  balance: null,
105
97
  };
106
98
 
107
- const quoteWarning = generateQuoteWarnings(currentQuote, {
108
- fromToken: params.fromToken,
109
- toToken: params.toToken,
110
- findToken: params.findToken,
111
- userSlippage: params.userSlippage,
99
+ const quoteWarning = generateQuoteWarnings({
100
+ previousQuote,
101
+ currentQuote,
102
+ findToken,
103
+ userSlippage,
112
104
  });
113
105
 
114
106
  if (quoteWarning) {
115
107
  output.quote = quoteWarning;
116
108
  }
117
109
 
118
- if (previousQuote && quoteChanged) {
119
- if (isOutputAmountChangedALot(previousQuote, currentQuote)) {
120
- output.quoteUpdate = {
121
- type: QuoteUpdateType.QUOTE_AND_OUTPUT_AMOUNT_UPDATED,
122
- newOutputAmount: numberToString(getQuoteOutputAmount(currentQuote)),
123
- percentageChange: numberToString(
124
- getPriceImpact(
125
- getQuoteOutputAmount(previousQuote) ?? '',
126
- getQuoteOutputAmount(currentQuote) ?? ''
127
- ),
128
- null,
129
- 2
130
- ),
131
- };
132
- } else if (isNumberOfSwapsChanged(previousQuote, currentQuote)) {
133
- output.quoteUpdate = {
134
- type: QuoteUpdateType.QUOTE_UPDATED,
135
- };
136
- } else if (isQuoteSwappersUpdated(previousQuote, currentQuote)) {
137
- output.quoteUpdate = {
138
- type: QuoteUpdateType.QUOTE_SWAPPERS_UPDATED,
139
- };
140
- } else if (isQuoteInternalCoinsUpdated(previousQuote, currentQuote)) {
141
- output.quoteUpdate = {
142
- type: QuoteUpdateType.QUOTE_COINS_UPDATED,
143
- };
144
- }
145
- }
146
-
147
110
  const balanceWarnings = generateBalanceWarnings(
148
111
  currentQuote,
149
- params.selectedWallets,
150
- params.meta.blockchains
112
+ selectedWallets,
113
+ meta.blockchains
151
114
  );
152
115
 
153
116
  const enoughBalance = balanceWarnings.length === 0;
@@ -21,10 +21,10 @@ export function useConfirmSwap(): ConfirmSwap {
21
21
  fromToken,
22
22
  toToken,
23
23
  inputAmount,
24
+ inputUsdValue,
24
25
  setSelectedQuote,
25
26
  selectedQuote: initialQuote,
26
27
  customDestination: customDestinationFromStore,
27
- setQuoteWarningsConfirmed,
28
28
  resetAlerts,
29
29
  } = useQuoteStore();
30
30
 
@@ -95,21 +95,16 @@ export function useConfirmSwap(): ConfirmSwap {
95
95
  disabledSwappersGroups: disabledLiquiditySources,
96
96
  };
97
97
 
98
- const confirmSwapWarnings = generateWarnings(
99
- initialQuote ?? undefined,
98
+ const confirmSwapWarnings = generateWarnings({
99
+ previousQuote: initialQuote ?? undefined,
100
100
  currentQuote,
101
- {
102
- fromToken,
103
- toToken,
104
- meta: { blockchains },
105
- findToken,
106
- selectedWallets,
107
- userSlippage,
108
- }
109
- );
110
- if (confirmSwapWarnings.quoteUpdate) {
111
- setQuoteWarningsConfirmed(false);
112
- }
101
+ meta: { blockchains },
102
+ selectedWallets,
103
+ userSlippage,
104
+ inputUsdValue,
105
+ findToken,
106
+ });
107
+
113
108
  resetAlerts();
114
109
 
115
110
  const proceedAnyway = !!confirmSwapWarnings.balance;
@@ -6,6 +6,9 @@ export type Watermark = 'NONE' | 'FULL';
6
6
  type ConfigResponse = {
7
7
  config: {
8
8
  watermark: Watermark;
9
+ banners: {
10
+ profile: boolean;
11
+ };
9
12
  };
10
13
  };
11
14
 
@@ -14,7 +17,7 @@ interface UseFetchApiConfig {
14
17
  }
15
18
 
16
19
  export function useFetchApiConfig(): UseFetchApiConfig {
17
- const { setWatermark } = useUiStore();
20
+ const { setWatermark, setShowProfileBanner } = useUiStore();
18
21
 
19
22
  const fetchApiConfig: UseFetchApiConfig['fetchApiConfig'] = async () => {
20
23
  const response = await fetch(
@@ -28,6 +31,7 @@ export function useFetchApiConfig(): UseFetchApiConfig {
28
31
  const data: ConfigResponse = await response.json();
29
32
 
30
33
  setWatermark(data.config.watermark);
34
+ setShowProfileBanner(data.config.banners.profile);
31
35
  };
32
36
  return { fetchApiConfig };
33
37
  }
@@ -103,6 +103,11 @@ export function useFetchCustomToken(): UseFetchCustomToken {
103
103
 
104
104
  return token;
105
105
  } catch (error: any) {
106
+ if (error?.code === 'ERR_BAD_REQUEST') {
107
+ const errorMessage = produceErrorMessage('not-found', blockchain);
108
+ setError(errorMessage);
109
+ return undefined;
110
+ }
106
111
  setError(undefined);
107
112
  throw new Error(error.message);
108
113
  } finally {
@@ -1,10 +1,8 @@
1
1
  import type { HandleConnectOptions, Result } from './useStatefulConnect.types';
2
2
  import type { WalletInfoWithExtra } from '../../types';
3
- import type {
4
- Namespace,
5
- NamespaceData,
6
- WalletType,
7
- } from '@rango-dev/wallets-shared';
3
+ import type { ExtendedModalWalletInfo } from '../../utils/wallets';
4
+ import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
5
+ import type { NamespaceData, WalletType } from '@rango-dev/wallets-shared';
8
6
 
9
7
  import { WalletState } from '@rango-dev/ui';
10
8
  import { useWallets } from '@rango-dev/wallets-react';
@@ -61,7 +59,11 @@ export function useStatefulConnect(): UseStatefulConnect {
61
59
  });
62
60
 
63
61
  try {
64
- await connect(type, undefined, namespaces);
62
+ const legacyNamespacesInput = namespaces?.map((namespaceInput) => ({
63
+ ...namespaceInput,
64
+ network: undefined,
65
+ }));
66
+ await connect(type, legacyNamespacesInput);
65
67
 
66
68
  return { status: ResultStatus.Connected };
67
69
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -75,7 +77,7 @@ export function useStatefulConnect(): UseStatefulConnect {
75
77
  };
76
78
 
77
79
  const handleConnect = async (
78
- wallet: WalletInfoWithExtra,
80
+ wallet: ExtendedModalWalletInfo,
79
81
  options?: HandleConnectOptions
80
82
  ): Promise<{
81
83
  status: ResultStatus;
@@ -83,31 +85,60 @@ export function useStatefulConnect(): UseStatefulConnect {
83
85
  const isDisconnected = wallet.state === WalletState.DISCONNECTED;
84
86
 
85
87
  if (isDisconnected) {
86
- if (!wallet.namespaces) {
88
+ // Legacy and hub have different structure to check wether we need to show namespace or not.
89
+
90
+ // Hub
91
+ const isHub = !!wallet.isHub;
92
+ if (isHub) {
93
+ const detachedInstances = wallet.properties?.find(
94
+ (item) => item.name === 'detached'
95
+ );
96
+ const needsNamespace =
97
+ detachedInstances && wallet.state !== 'connected';
98
+
99
+ if (needsNamespace) {
100
+ dispatch({
101
+ type: 'needsNamespace',
102
+ payload: {
103
+ targetWallet: wallet,
104
+ },
105
+ });
106
+ return { status: ResultStatus.Namespace };
107
+ }
108
+ }
109
+
110
+ /*
111
+ * Legacy
112
+ *
113
+ * For legacy there are 3 states:
114
+ * 1. a wallet doesn't have any namespace defined, we call the connect.
115
+ * 2. a wallet has more than two namespaces, we should show namepsace modal, and in that place user will be checked to needs derivation path or not.
116
+ * 3. a wallet has exactly one namespacesape, in this case we check if that needs derivation or not, if it needs we will do it here by dispatching the action accordingly.
117
+ */
118
+ if (!wallet.needsNamespace) {
87
119
  return await runConnect(wallet.type, undefined, options);
88
120
  }
89
121
 
90
- const needsNamespace = wallet.namespaces.length > 1;
122
+ const needsNamespace = wallet.needsNamespace.data.length > 1;
91
123
  const needsDerivationPath = wallet.needsDerivationPath;
92
124
 
93
125
  if (needsNamespace) {
94
126
  dispatch({
95
127
  type: 'needsNamespace',
96
128
  payload: {
97
- providerType: wallet.type,
98
- providerImage: wallet.image,
99
- availableNamespaces: wallet.namespaces,
100
- singleNamespace: wallet.singleNamespace,
129
+ targetWallet: wallet,
101
130
  },
102
131
  });
103
132
  return { status: ResultStatus.Namespace };
104
133
  } else if (needsDerivationPath) {
134
+ const namespace = wallet.needsNamespace.data[0];
135
+
105
136
  dispatch({
106
137
  type: 'needsDerivationPath',
107
138
  payload: {
108
139
  providerType: wallet.type,
109
140
  providerImage: wallet.image,
110
- namespace: wallet.namespaces[0],
141
+ namespace: namespace.value,
111
142
  },
112
143
  });
113
144
  return { status: ResultStatus.DerivationPath };
@@ -115,7 +146,9 @@ export function useStatefulConnect(): UseStatefulConnect {
115
146
 
116
147
  return await runConnect(
117
148
  wallet.type,
118
- wallet.namespaces.map((namespace) => ({ namespace })),
149
+ wallet.needsNamespace?.data.map((namespace) => ({
150
+ namespace: namespace.value,
151
+ })),
119
152
  options
120
153
  );
121
154
  }
@@ -132,7 +165,7 @@ export function useStatefulConnect(): UseStatefulConnect {
132
165
  wallet: WalletInfoWithExtra,
133
166
  selectedNamespaces: Namespace[]
134
167
  ): Promise<Result> => {
135
- const isSingleNamespace = wallet.singleNamespace;
168
+ const isSingleNamespace = wallet.needsNamespace?.selection === 'single';
136
169
  const needsDerivationPath = wallet.needsDerivationPath;
137
170
  const firstSelectedNamespace = selectedNamespaces[0];
138
171
 
@@ -172,7 +205,7 @@ export function useStatefulConnect(): UseStatefulConnect {
172
205
  );
173
206
  }
174
207
 
175
- const type = connectState.namespace.providerType;
208
+ const type = connectState.namespace.targetWallet.type;
176
209
  const namespaces = selectedNamespaces.map((namespace) => ({
177
210
  namespace,
178
211
  }));
@@ -1,4 +1,5 @@
1
- import type { Namespace } from '@rango-dev/wallets-shared';
1
+ import type { ExtendedModalWalletInfo } from '../../utils/wallets';
2
+ import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
2
3
 
3
4
  export interface HandleConnectOptions {
4
5
  // To have a switch between connect and disconnect when user is clicking on a button, this option can be helpful.
@@ -6,10 +7,7 @@ export interface HandleConnectOptions {
6
7
  }
7
8
 
8
9
  export interface NeedsNamespacesState {
9
- providerType: string;
10
- providerImage: string;
11
- availableNamespaces?: Namespace[];
12
- singleNamespace?: boolean;
10
+ targetWallet: ExtendedModalWalletInfo;
13
11
  }
14
12
 
15
13
  export interface NeedsDerivationPathState {
@@ -12,13 +12,10 @@ import { useEffect } from 'react';
12
12
  import { eventEmitter } from '../../services/eventEmitter';
13
13
  import { useAppStore } from '../../store/AppStore';
14
14
  import { useNotificationStore } from '../../store/notification';
15
- import { useWalletsStore } from '../../store/wallets';
16
15
 
17
16
  export function useSubscribeToWidgetEvents() {
18
- const connectedWallets = useWalletsStore.use.connectedWallets();
19
- const getWalletsDetails = useWalletsStore.use.getWalletsDetails();
20
17
  const setNotification = useNotificationStore.use.setNotification();
21
- const { findToken } = useAppStore();
18
+ const { connectedWallets, fetchBalances } = useAppStore();
22
19
 
23
20
  useEffect(() => {
24
21
  const handleStepEvent = (widgetEvent: StepEventData) => {
@@ -39,8 +36,12 @@ export function useSubscribeToWidgetEvents() {
39
36
  (wallet) => wallet.chain === step?.toBlockchain
40
37
  );
41
38
 
42
- fromAccount && getWalletsDetails([fromAccount], findToken);
43
- toAccount && getWalletsDetails([toAccount], findToken);
39
+ if (fromAccount) {
40
+ void fetchBalances([fromAccount]);
41
+ }
42
+ if (toAccount) {
43
+ void fetchBalances([toAccount]);
44
+ }
44
45
  }
45
46
 
46
47
  setNotification(event, route);
@@ -4,15 +4,12 @@ import { useCallback, useEffect, useRef, useState } from 'react';
4
4
 
5
5
  import { useAppStore } from '../store/AppStore';
6
6
  import { useQuoteStore } from '../store/quote';
7
- import { useWalletsStore } from '../store/wallets';
8
7
  import { QuoteErrorType } from '../types';
9
8
  import { debounce } from '../utils/common';
10
9
  import { isPositiveNumber } from '../utils/numbers';
11
10
  import {
12
11
  generateQuoteWarnings,
13
12
  getDefaultQuote,
14
- getQuoteFromTokenUsdPrice,
15
- getQuoteToTokenUsdPrice,
16
13
  sortQuotesBy,
17
14
  } from '../utils/quote';
18
15
  import { isRoutingEnabled } from '../utils/settings';
@@ -50,7 +47,7 @@ export function useSwapInput({
50
47
  const { fetch: fetchQuote, cancelFetch } = useFetchAllQuotes();
51
48
  const { excludeLiquiditySources: configExcludeLiquiditySources, routing } =
52
49
  useAppStore().config;
53
- const connectedWallets = useWalletsStore.use.connectedWallets();
50
+ const { connectedWallets } = useAppStore();
54
51
 
55
52
  const {
56
53
  fromToken,
@@ -157,15 +154,10 @@ export function useSwapInput({
157
154
  requestId: quote?.requestId || '',
158
155
  swaps: quote?.swaps,
159
156
  });
160
- const outputUsdValue =
161
- getQuoteToTokenUsdPrice(quote) || toToken?.usdPrice;
162
- const inputUsdValue =
163
- getQuoteFromTokenUsdPrice(quote) || fromToken?.usdPrice;
164
157
  const quoteWarning =
165
158
  quote &&
166
- generateQuoteWarnings(quote, {
167
- fromToken: { ...fromToken, usdPrice: inputUsdValue },
168
- toToken: { ...toToken, usdPrice: outputUsdValue },
159
+ generateQuoteWarnings({
160
+ currentQuote: quote,
169
161
  userSlippage,
170
162
  findToken,
171
163
  });
@@ -12,7 +12,6 @@ import {
12
12
  import { useCallback, useEffect } from 'react';
13
13
 
14
14
  import { useAppStore } from '../store/AppStore';
15
- import { useWalletsStore } from '../store/wallets';
16
15
  import { configWalletsToWalletName } from '../utils/providers';
17
16
  import {
18
17
  hashWalletsState,
@@ -23,8 +22,6 @@ import {
23
22
 
24
23
  import { useStatefulConnect } from './useStatefulConnect/useStatefulConnect';
25
24
 
26
- const ALL_SUPPORTED_WALLETS = Object.values(WalletTypes);
27
-
28
25
  interface Params {
29
26
  chain?: string;
30
27
  }
@@ -43,21 +40,22 @@ interface API {
43
40
  */
44
41
  export function useWalletList(params?: Params): API {
45
42
  const { chain } = params || {};
46
- const { config } = useAppStore();
43
+ const { config, connectedWallets, getAvailableProviders } = useAppStore();
47
44
  const { state, getWalletInfo } = useWallets();
48
- const { connectedWallets } = useWalletsStore();
49
45
  const blockchains = useAppStore().blockchains();
50
46
  const { handleDisconnect } = useStatefulConnect();
51
47
 
52
48
  /** It can be what has been set by widget config or as a fallback we use all the supported wallets by our library */
53
- const listAvailableWalletTypes =
54
- configWalletsToWalletName(config?.wallets, {
49
+ const listAvailableWalletTypes = configWalletsToWalletName(
50
+ getAvailableProviders(),
51
+ {
55
52
  trezorManifest: config?.trezorManifest,
56
53
  walletConnectProjectId: config?.walletConnectProjectId,
57
54
  walletConnectListedDesktopWalletLink:
58
55
  config.__UNSTABLE_OR_INTERNAL__?.walletConnectListedDesktopWalletLink,
59
56
  tonConnect: config.tonConnect,
60
- }) || ALL_SUPPORTED_WALLETS;
57
+ }
58
+ );
61
59
 
62
60
  let wallets = mapWalletTypesToWalletInfo(
63
61
  state,
@@ -1,34 +1,30 @@
1
1
  import type { WidgetConfig } from '../../types';
2
2
  import type { ProvidersOptions } from '../../utils/providers';
3
- import type { ProviderInterface } from '@rango-dev/wallets-react';
4
3
 
5
4
  import { useEffect } from 'react';
6
5
 
7
- import { useWalletsStore } from '../../store/wallets';
8
- import { matchAndGenerateProviders } from '../../utils/providers';
6
+ import { useAppStore } from '../../store/AppStore';
9
7
 
10
8
  import { hashProviders } from './useWalletProviders.helpers';
11
9
 
12
10
  export function useWalletProviders(
13
- providers: WidgetConfig['wallets'],
11
+ configWallets: WidgetConfig['wallets'],
14
12
  options?: ProvidersOptions
15
13
  ) {
16
- const clearConnectedWallet = useWalletsStore.use.clearConnectedWallet();
17
- let generateProviders: ProviderInterface[] = matchAndGenerateProviders(
18
- providers,
19
- options
20
- );
14
+ const { clearConnectedWallet, getAvailableProviders, buildAndSetProviders } =
15
+ useAppStore();
16
+ const providers = getAvailableProviders();
21
17
 
22
18
  useEffect(() => {
23
19
  clearConnectedWallet();
24
- generateProviders = matchAndGenerateProviders(providers, options);
20
+ buildAndSetProviders();
25
21
  }, [
26
- hashProviders(providers ?? []),
22
+ hashProviders(configWallets ?? []),
27
23
  options?.walletConnectProjectId,
28
24
  options?.walletConnectListedDesktopWalletLink,
29
25
  ]);
30
26
 
31
27
  return {
32
- providers: generateProviders,
28
+ providers,
33
29
  };
34
30
  }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { WidgetProps } from './containers/Widget';
2
- import type { ConnectedWallet } from './store/wallets';
2
+ import type { ConnectedWallet } from './store/slices/wallets';
3
3
  import type {
4
4
  BlockchainAndTokenConfig,
5
5
  QuoteEventData,
@@ -24,12 +24,12 @@ import { RefreshButton } from '../components/HeaderButtons/RefreshButton';
24
24
  import { Layout, PageContainer } from '../components/Layout';
25
25
  import { QuoteWarningsAndErrors } from '../components/QuoteWarningsAndErrors';
26
26
  import { navigationRoutes } from '../constants/navigationRoutes';
27
- import { getQuoteUpdateWarningMessage } from '../constants/warnings';
28
27
  import { QuoteInfo } from '../containers/QuoteInfo';
29
28
  import { useConfirmSwap } from '../hooks/useConfirmSwap';
30
29
  import { useAppStore } from '../store/AppStore';
31
30
  import { useQuoteStore } from '../store/quote';
32
31
  import { useUiStore } from '../store/ui';
32
+ import { isQuoteWarningConfirmationRequired } from '../utils/quote';
33
33
  import { joinList } from '../utils/ui';
34
34
 
35
35
  const Buttons = styled('div', {
@@ -133,7 +133,12 @@ export function ConfirmSwapPage() {
133
133
  };
134
134
 
135
135
  const onStartConfirmSwap = async () => {
136
- if (confirmSwapResult?.warnings?.quote && !quoteWarningsConfirmed) {
136
+ const shouldShowWarningModal =
137
+ confirmSwapResult.warnings?.quote &&
138
+ isQuoteWarningConfirmationRequired(confirmSwapResult.warnings.quote) &&
139
+ !quoteWarningsConfirmed;
140
+
141
+ if (shouldShowWarningModal) {
137
142
  setShowQuoteWarningModal(true);
138
143
  } else {
139
144
  await onConfirm();
@@ -196,19 +201,6 @@ export function ConfirmSwapPage() {
196
201
  alerts.push(<Alert type="error" variant="alarm" title={dbErrorMessage} />);
197
202
  }
198
203
 
199
- if (confirmSwapResult.warnings?.quoteUpdate) {
200
- alerts.push(
201
- <Alert
202
- variant="alarm"
203
- type="warning"
204
- title={
205
- confirmSwapResult.warnings.quoteUpdate &&
206
- getQuoteUpdateWarningMessage(confirmSwapResult.warnings.quoteUpdate)
207
- }
208
- />
209
- );
210
- }
211
-
212
204
  if (quoteWarning || quoteError) {
213
205
  const settings_url = `../${navigationRoutes.settings}`;
214
206
  alerts.push(
@@ -19,7 +19,6 @@ import { useSwapInput } from '../hooks/useSwapInput';
19
19
  import { useAppStore } from '../store/AppStore';
20
20
  import { useQuoteStore } from '../store/quote';
21
21
  import { useUiStore } from '../store/ui';
22
- import { useWalletsStore } from '../store/wallets';
23
22
  import { UiEventTypes } from '../types';
24
23
  import { isVariantExpandable } from '../utils/configs';
25
24
  import { emitPreventableEvent } from '../utils/events';
@@ -55,9 +54,12 @@ export function Home() {
55
54
  const { isLargeScreen, isExtraLargeScreen } = useScreenDetect();
56
55
 
57
56
  const { fetch: fetchQuote, loading } = useSwapInput({ refetchQuote });
58
- const { config, fetchStatus: fetchMetaStatus } = useAppStore();
57
+ const {
58
+ config,
59
+ fetchStatus: fetchMetaStatus,
60
+ connectedWallets,
61
+ } = useAppStore();
59
62
 
60
- const { connectedWallets } = useWalletsStore();
61
63
  const { isActiveTab } = useUiStore();
62
64
  const [showQuoteWarningModal, setShowQuoteWarningModal] = useState(false);
63
65
 
@@ -13,7 +13,6 @@ import { navigationRoutes } from '../constants/navigationRoutes';
13
13
  import { useNavigateBack } from '../hooks/useNavigateBack';
14
14
  import { useAppStore } from '../store/AppStore';
15
15
  import { useQuoteStore } from '../store/quote';
16
- import { useWalletsStore } from '../store/wallets';
17
16
 
18
17
  interface PropTypes {
19
18
  type: 'source' | 'destination';
@@ -31,7 +30,7 @@ export function SelectSwapItemsPage(props: PropTypes) {
31
30
  setFromBlockchain,
32
31
  setToBlockchain,
33
32
  } = useQuoteStore();
34
- const getBalanceFor = useWalletsStore.use.getBalanceFor();
33
+ const { getBalanceFor } = useAppStore();
35
34
  const [searchedFor, setSearchedFor] = useState<string>('');
36
35
 
37
36
  const selectedBlockchain = type === 'source' ? fromBlockchain : toBlockchain;
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),