@rango-dev/widget-embedded 0.12.1-next.14 → 0.12.1-next.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/widget-embedded",
3
- "version": "0.12.1-next.14",
3
+ "version": "0.12.1-next.15",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/src/Widget.tsx CHANGED
@@ -11,9 +11,12 @@ import { WidgetEvents } from './components/WidgetEvents';
11
11
  import { globalFont } from './globalStyles';
12
12
  import { useTheme } from './hooks/useTheme';
13
13
  import QueueManager from './QueueManager';
14
+ import { useBestRouteStore } from './store/bestRoute';
15
+ import { useMetaStore } from './store/meta';
14
16
  import { useNotificationStore } from './store/notification';
15
17
  import { useSettingsStore } from './store/settings';
16
18
  import { initConfig } from './utils/configs';
19
+ import { tokensAreEqual } from './utils/wallets';
17
20
  import { WidgetContext, WidgetWallets } from './Wallets';
18
21
 
19
22
  const MainContainer = styled('div', {
@@ -52,6 +55,63 @@ export function Main(props: PropsWithChildren<WidgetProps>) {
52
55
  widgetContext.onConnectWallet(setLastConnectedWalletWithNetwork);
53
56
  }, []);
54
57
 
58
+ const {
59
+ setInputAmount,
60
+ setToToken,
61
+ setToBlockchain,
62
+ setFromBlockchain,
63
+ setFromToken,
64
+ } = useBestRouteStore();
65
+
66
+ const {
67
+ meta: { tokens, blockchains },
68
+ loadingStatus: loadingMetaStatus,
69
+ } = useMetaStore();
70
+
71
+ const { setAffiliateRef, setAffiliatePercent, setAffiliateWallets } =
72
+ useSettingsStore();
73
+
74
+ useEffect(() => {
75
+ setInputAmount(config?.amount?.toString() || '');
76
+ }, [config?.amount]);
77
+
78
+ useEffect(() => {
79
+ if (loadingMetaStatus === 'success') {
80
+ const chain = blockchains.find(
81
+ (chain) => chain.name === config?.from?.blockchain
82
+ );
83
+ const token = tokens.find((t) =>
84
+ tokensAreEqual(t, config?.from?.token || null)
85
+ );
86
+
87
+ setFromBlockchain(chain || null);
88
+ setFromToken(token || null);
89
+ }
90
+ }, [config?.from?.token, config?.from?.blockchain, loadingMetaStatus]);
91
+
92
+ useEffect(() => {
93
+ if (loadingMetaStatus === 'success') {
94
+ const chain = blockchains.find(
95
+ (chain) => chain.name === config?.to?.blockchain
96
+ );
97
+ const token = tokens.find((t) =>
98
+ tokensAreEqual(t, config?.to?.token || null)
99
+ );
100
+ setToBlockchain(chain || null);
101
+ setToToken(token || null);
102
+ }
103
+ }, [config?.to?.token, config?.to?.blockchain, loadingMetaStatus]);
104
+
105
+ useEffect(() => {
106
+ setAffiliateRef(config?.affiliate?.ref ?? null);
107
+ setAffiliatePercent(config?.affiliate?.percent ?? null);
108
+ setAffiliateWallets(config?.affiliate?.wallets ?? null);
109
+ }, [
110
+ config?.affiliate?.ref,
111
+ config?.affiliate?.percent,
112
+ config?.affiliate?.wallets,
113
+ ]);
114
+
55
115
  return (
56
116
  <I18nManager language={config?.language}>
57
117
  <MainContainer id="swap-container" className={activeTheme}>
@@ -98,7 +98,7 @@ export function useSwapInput(): UseSwapInput {
98
98
  setLoading(true);
99
99
  debouncedFetch();
100
100
  return cancelFetch;
101
- }, [inputAmount]);
101
+ }, [inputAmount, shouldSkipRequest]);
102
102
 
103
103
  useEffect(() => {
104
104
  if (!shouldSkipRequest) {