@rango-dev/widget-embedded 0.17.1-next.21 → 0.17.1-next.22
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.
- package/dist/components/UpdateUrl.d.ts.map +1 -1
- package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
- package/dist/hooks/useSyncStoresWithConfig.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
- package/src/components/UpdateUrl.tsx +0 -2
- package/src/containers/Wallets/Wallets.tsx +2 -0
- package/src/hooks/useSyncStoresWithConfig.ts +17 -3
package/package.json
CHANGED
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
|
|
8
8
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
9
9
|
import { SearchParams } from '../constants/searchParams';
|
|
10
|
-
import { useSyncStoresWithConfig } from '../hooks/useSyncStoresWithConfig';
|
|
11
10
|
import { useAppStore } from '../store/AppStore';
|
|
12
11
|
import { useQuoteStore } from '../store/quote';
|
|
13
12
|
import { useUiStore } from '../store/ui';
|
|
@@ -33,7 +32,6 @@ export function UpdateUrl() {
|
|
|
33
32
|
const blockchains = useAppStore().blockchains();
|
|
34
33
|
const tokens = useAppStore().tokens();
|
|
35
34
|
const setSelectedSwap = useUiStore.use.setSelectedSwap();
|
|
36
|
-
useSyncStoresWithConfig();
|
|
37
35
|
|
|
38
36
|
useEffect(() => {
|
|
39
37
|
const params: Record<string, string> = {};
|
|
@@ -12,6 +12,7 @@ import { Events, Provider } from '@rango-dev/wallets-react';
|
|
|
12
12
|
import { isEvmBlockchain } from 'rango-sdk';
|
|
13
13
|
import React, { createContext, useEffect, useRef } from 'react';
|
|
14
14
|
|
|
15
|
+
import { useSyncStoresWithConfig } from '../../hooks/useSyncStoresWithConfig';
|
|
15
16
|
import { useWalletProviders } from '../../hooks/useWalletProviders';
|
|
16
17
|
import { AppStoreProvider, useAppStore } from '../../store/AppStore';
|
|
17
18
|
import { useWalletsStore } from '../../store/wallets';
|
|
@@ -37,6 +38,7 @@ function Main(props: PropsWithChildren<PropTypes>) {
|
|
|
37
38
|
const disconnectWallet = useWalletsStore.use.disconnectWallet();
|
|
38
39
|
const connectWallet = useWalletsStore.use.connectWallet();
|
|
39
40
|
const onConnectWalletHandler = useRef<OnConnectHandler>();
|
|
41
|
+
useSyncStoresWithConfig();
|
|
40
42
|
|
|
41
43
|
useEffect(() => {
|
|
42
44
|
if (props.config) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Asset } from 'rango-sdk';
|
|
2
2
|
|
|
3
|
-
import { useEffect, useMemo, useRef } from 'react';
|
|
3
|
+
import { useEffect, useLayoutEffect, useMemo, useRef } from 'react';
|
|
4
4
|
|
|
5
5
|
import { useAppStore } from '../store/AppStore';
|
|
6
6
|
import { useQuoteStore } from '../store/quote';
|
|
@@ -53,7 +53,14 @@ export function useSyncStoresWithConfig() {
|
|
|
53
53
|
setInputAmount(config?.amount?.toString() || '');
|
|
54
54
|
}, [config?.amount]);
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
/*
|
|
57
|
+
* We update quote tokens in two scenarios.
|
|
58
|
+
* If default values exist in widget config or search parameters exist in URL.
|
|
59
|
+
* The logic for updating quote store exists in two useEffect in two locations, and they run in order.If default tokens for quote exist in widget config and also exist in URL, widget config values take precedence over URL values, and URL search parameters don’t affect the widget.
|
|
60
|
+
* Using useLayoutEffect causes widget config values to apply first.
|
|
61
|
+
* We may consider replacing this with a better solution in the future.
|
|
62
|
+
*/
|
|
63
|
+
useLayoutEffect(() => {
|
|
57
64
|
if (fetchMetaStatus === 'success') {
|
|
58
65
|
const chain = blockchains.find(
|
|
59
66
|
(chain) => chain.name === config?.from?.blockchain
|
|
@@ -111,7 +118,14 @@ export function useSyncStoresWithConfig() {
|
|
|
111
118
|
}
|
|
112
119
|
}, [toTokensConfig, toBlockchainsConfig]);
|
|
113
120
|
|
|
114
|
-
|
|
121
|
+
/*
|
|
122
|
+
* We update quote tokens in two scenarios.
|
|
123
|
+
* If default values exist in widget config or search parameters exist in URL.
|
|
124
|
+
* The logic for updating quote store exists in two useEffect in two locations, and they run in order.If default tokens for quote exist in widget config and also exist in URL, widget config values take precedence over URL values, and URL search parameters don’t affect the widget.
|
|
125
|
+
* Using useLayoutEffect causes widget config values to apply first.
|
|
126
|
+
* We may consider replacing this with a better solution in the future.
|
|
127
|
+
*/
|
|
128
|
+
useLayoutEffect(() => {
|
|
115
129
|
if (fetchMetaStatus === 'success') {
|
|
116
130
|
const chain = blockchains.find(
|
|
117
131
|
(chain) => chain.name === config?.to?.blockchain
|