Skip to content

Commit 2e2c3e8

Browse files
fix: fix bugs after rebase
1 parent bb8c06c commit 2e2c3e8

File tree

12 files changed

+103
-75
lines changed

12 files changed

+103
-75
lines changed

widget/embedded/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@
5454
"publishConfig": {
5555
"access": "public"
5656
}
57-
}
57+
}

widget/embedded/src/containers/Wallets/useUpdates.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { type Network } from '@rango-dev/wallets-shared';
1717
import { isEvmBlockchain } from 'rango-sdk';
1818

1919
import { useAppStore } from '../../store/AppStore';
20+
import { useQuoteStore } from '../../store/quote';
2021
import {
2122
prepareAccountsForWalletStore,
2223
walletAndSupportedChainsNames,
@@ -43,6 +44,7 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
4344
removeBalancesForWallet,
4445
blockchains,
4546
} = useAppStore();
47+
const quoteStore = useQuoteStore()();
4648

4749
const { onConnectWalletHandler, onDisconnectWalletHandler } = params;
4850
const evmBasedChainNames = blockchains()
@@ -77,7 +79,12 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
7779
);
7880

7981
if (data.length) {
80-
void newWalletConnected(data, info.namespace, state.derivationPath);
82+
void newWalletConnected(
83+
quoteStore,
84+
data,
85+
info.namespace,
86+
state.derivationPath
87+
);
8188
}
8289
};
8390

@@ -101,7 +108,7 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
101108
}
102109

103110
if (event === Events.PROVIDER_DISCONNECTED) {
104-
disconnectWallet(type);
111+
disconnectWallet(type, quoteStore);
105112
if (!!onDisconnectWalletHandler.current) {
106113
onDisconnectWalletHandler.current(type);
107114
} else {
@@ -112,7 +119,7 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
112119
}
113120

114121
if (event === Events.NAMESPACE_DISCONNECTED) {
115-
disconnectNamespaces(type, value);
122+
disconnectNamespaces(type, value, quoteStore);
116123
}
117124
};
118125

@@ -186,7 +193,7 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
186193
supportedChainNames,
187194
});
188195
} else {
189-
disconnectWallet(type);
196+
disconnectWallet(type, quoteStore);
190197
if (!!onDisconnectWalletHandler.current) {
191198
onDisconnectWalletHandler.current(type);
192199
} else {

widget/embedded/src/hooks/useConfirmSwap/useConfirmSwap.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export function useConfirmSwap() {
1010
const { loading, cancelFetch, fetch: confirmSwap, addSwap } = useHandleSwap();
1111
const sourceWallet = useAppStore().selectedWallet('source');
1212
const destinationWallet = useAppStore().selectedWallet('destination');
13-
const { customDestination, confirmSwapData } = useQuoteStore()();
13+
const { customDestination, confirmSwapData, setConfirmSwapData } =
14+
useQuoteStore()();
1415

1516
const [confirmSwapResult, setConfirmSwapResult] =
1617
useState<ConfirmSwapFetchResult | null>({
@@ -35,11 +36,9 @@ export function useConfirmSwap() {
3536
return;
3637
}
3738

38-
useQuoteStore.setState({
39-
confirmSwapData: {
40-
proceedAnyway: false,
41-
quoteData: result.quoteData,
42-
},
39+
setConfirmSwapData({
40+
proceedAnyway: false,
41+
quoteData: result.quoteData,
4342
});
4443
};
4544

widget/embedded/src/hooks/useHandleSwap/useHandleSwap.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { useQuoteStore } from '../../store/quote';
1212
import { QuoteErrorType } from '../../types';
1313
import { getWalletsForNewSwap } from '../../utils/swap';
1414
import { useFetchConfirmQuote } from '../useFetchConfirmQuote';
15+
import { useSwapMode } from '../useSwapMode';
1516

1617
import {
1718
generateWarnings,
@@ -30,8 +31,9 @@ export function useHandleSwap(): ConfirmSwap {
3031
customDestination: customDestinationFromStore,
3132
confirmSwapData,
3233
resetAlerts,
33-
} = useQuoteStore();
34+
} = useQuoteStore()();
3435
const { manager } = useManager();
36+
const { swapMode } = useSwapMode();
3537

3638
const { slippage, customSlippage, disabledLiquiditySources } = useAppStore();
3739
const blockchains = useAppStore().blockchains();
@@ -143,14 +145,15 @@ export function useHandleSwap(): ConfirmSwap {
143145
disabledSwappersGroups: disabledLiquiditySources,
144146
};
145147

146-
const swap = calculatePendingSwap(
147-
inputAmount.toString(),
148-
data,
149-
getWalletsForNewSwap(selectedWalletsForConfirmation ?? []),
150-
swapSettings,
151-
confirmSwapData.proceedAnyway,
152-
{ blockchains, tokens }
153-
);
148+
const swap = calculatePendingSwap({
149+
inputAmount: inputAmount.toString(),
150+
bestRoute: data,
151+
wallets: getWalletsForNewSwap(selectedWalletsForConfirmation ?? []),
152+
settings: swapSettings,
153+
validateBalanceOrFee: confirmSwapData.proceedAnyway,
154+
meta: { blockchains, tokens },
155+
swapMode,
156+
});
154157
await manager?.create(
155158
'swap',
156159
{ swapDetails: swap },

widget/embedded/src/hooks/useUpdateSelectedWallets.ts/useUpdateSelectedWallets.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@ import { useQuoteStore } from '../../store/quote';
1313
* and trigger the wallet update method accordingly.
1414
*/
1515
export function useUpdateSelectedWallets() {
16-
const { fromToken, toToken, setCustomDestination } = useQuoteStore()();
16+
const quoteStore = useQuoteStore()();
17+
const { fromToken, toToken, setCustomDestination } = quoteStore;
1718
const {
1819
clearSelectedWallet,
1920
tryMatchWalletForBlockchain,
2021
isSelectedWalletStillRelevant,
2122
} = useAppStore();
2223

2324
useEffect(() => {
24-
const shouldUpdateSourceWallet = !isSelectedWalletStillRelevant('source');
25+
const shouldUpdateSourceWallet = !isSelectedWalletStillRelevant(
26+
'source',
27+
quoteStore
28+
);
2529
if (shouldUpdateSourceWallet) {
2630
clearSelectedWallet('source');
2731
if (fromToken) {
@@ -33,8 +37,10 @@ export function useUpdateSelectedWallets() {
3337
useEffect(() => {
3438
setCustomDestination(null);
3539

36-
const shouldUpdateDestinationWallet =
37-
!isSelectedWalletStillRelevant('destination');
40+
const shouldUpdateDestinationWallet = !isSelectedWalletStillRelevant(
41+
'destination',
42+
quoteStore
43+
);
3844
if (shouldUpdateDestinationWallet) {
3945
clearSelectedWallet('destination');
4046
if (toToken) {

widget/embedded/src/pages/ConfirmSwapPage.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export function ConfirmSwapPage() {
6161
quoteWarningsConfirmed,
6262
confirmSwapData,
6363
setInputAmount,
64+
setConfirmSwapData,
6465
} = useQuoteStore()();
6566
const { disabledLiquiditySources } = useAppStore();
6667
const { isActiveTab } = useUiStore();
@@ -140,11 +141,9 @@ export function ConfirmSwapPage() {
140141
};
141142

142143
const onConfirmBalanceWarning = async () => {
143-
useQuoteStore.setState({
144-
confirmSwapData: {
145-
proceedAnyway: true,
146-
quoteData: confirmSwapResult?.quoteData,
147-
},
144+
setConfirmSwapData({
145+
proceedAnyway: true,
146+
quoteData: confirmSwapResult?.quoteData,
148147
});
149148
await addNewSwap();
150149
};

widget/embedded/src/pages/DestinationWalletPage/DestinationWalletPage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import {
3434
const NUMBER_OF_WALLETS_TO_DISPLAY = 2;
3535

3636
export function DestinationWalletPage() {
37-
const { toBlockchain, customDestination, setCustomDestination } =
38-
useQuoteStore();
37+
const quoteStore = useQuoteStore()();
38+
const { toBlockchain, customDestination, setCustomDestination } = quoteStore;
3939
const destinationWallet = useAppStore().selectedWallet('destination');
4040
const {
4141
setSelectedWallet,
@@ -68,7 +68,7 @@ export function DestinationWalletPage() {
6868
setShowCustomDestinationMessage(true);
6969
}
7070

71-
return checkAndClearCustomDestinationIfNeeded;
71+
return () => checkAndClearCustomDestinationIfNeeded(quoteStore);
7272
}, []);
7373

7474
if (!toBlockchain) {

widget/embedded/src/pages/Home.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export function Home() {
5858
resetQuoteWallets,
5959
setQuoteWarningsConfirmed,
6060
updateQuotePartialState,
61+
setConfirmSwapData,
6162
} = useQuoteStore()();
6263

6364
const [isVisibleExpanded, setIsVisibleExpanded] = useState<boolean>(false);
@@ -218,11 +219,9 @@ export function Home() {
218219

219220
const onConfirmBalanceWarning = () => {
220221
if (confirmSwapResult?.quoteData) {
221-
useQuoteStore.setState({
222-
confirmSwapData: {
223-
proceedAnyway: true,
224-
quoteData: confirmSwapResult?.quoteData,
225-
},
222+
setConfirmSwapData({
223+
proceedAnyway: true,
224+
quoteData: confirmSwapResult?.quoteData,
226225
});
227226
navigate(navigationRoutes.confirmSwap);
228227
}

widget/embedded/src/pages/RouteWalletsPage/RouteWalletsPage.helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import { getQuoteChains } from '../../utils/wallets';
55
export function getRouteBlockchains(quote: SelectedQuote): string[] {
66
return getQuoteChains({ quote, filter: 'required' }).filter(
77
// Since the source wallet is selected on the source page, we don't include it here.
8-
(blockchain) => blockchain !== quote.swaps[0].from.blockchain
8+
(blockchain) => blockchain !== quote.swaps[0]?.from.blockchain
99
);
1010
}

widget/embedded/src/pages/RouteWalletsPage/RouteWalletsPage.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ export function SupportedWallets(props: SupportedWalletsPropTypes) {
5858
}
5959

6060
export function RouteWalletsPage() {
61-
const { selectedQuote } = useQuoteStore();
61+
const quoteStore = useQuoteStore()();
62+
const { selectedQuote, setConfirmSwapData } = quoteStore;
6263
const routeWallets = useAppStore().selectedWallet('route');
6364
const { connectedWallets, setSelectedWallet, suggestRouteWallets } =
6465
useAppStore();
@@ -78,7 +79,7 @@ export function RouteWalletsPage() {
7879
!!confirmSwapResult?.warnings?.balance?.messages;
7980

8081
useEffect(() => {
81-
suggestRouteWallets();
82+
suggestRouteWallets(quoteStore);
8283
}, []);
8384

8485
useEffect(() => {
@@ -122,11 +123,9 @@ export function RouteWalletsPage() {
122123

123124
const onConfirmBalanceWarning = () => {
124125
if (confirmSwapResult?.quoteData) {
125-
useQuoteStore.setState({
126-
confirmSwapData: {
127-
proceedAnyway: true,
128-
quoteData: confirmSwapResult.quoteData,
129-
},
126+
setConfirmSwapData({
127+
proceedAnyway: true,
128+
quoteData: confirmSwapResult.quoteData,
130129
});
131130
navigateToConfirmSwapPage();
132131
}

0 commit comments

Comments
 (0)