@rango-dev/widget-embedded 0.1.16-next.1 → 0.1.16-next.2
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/Layout.d.ts.map +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/widget-embedded.cjs.development.js +15 -10
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +15 -10
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +15 -10
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +2 -6
- package/src/components/Layout.tsx +22 -18
- package/src/index.tsx +144 -14
- package/dist/App.d.ts +0 -9
- package/dist/App.d.ts.map +0 -1
- package/dist/lib.d.ts +0 -10
- package/dist/lib.d.ts.map +0 -1
- package/src/App.tsx +0 -123
- package/src/app.css +0 -12
- package/src/lib.tsx +0 -144
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/widget-embedded",
|
|
3
|
-
"version": "0.1.16-next.
|
|
3
|
+
"version": "0.1.16-next.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -10,11 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"browserslist": "> 0.5%, last 2 versions, not dead",
|
|
12
12
|
"scripts": {
|
|
13
|
-
"
|
|
14
|
-
"dev": "parcel public/index.html -p 3001 --no-cache",
|
|
15
|
-
"dev-tsc": "npm-run-all --parallel watch-tsc dev",
|
|
16
|
-
"build:app": "parcel build --cache-dir=.parcel-cache",
|
|
17
|
-
"build": "tsdx build --entry ./src/lib.tsx"
|
|
13
|
+
"build": "tsdx build"
|
|
18
14
|
},
|
|
19
15
|
"husky": {
|
|
20
16
|
"hooks": {
|
|
@@ -71,31 +71,35 @@ export function Layout({ config }: LayoutProps) {
|
|
|
71
71
|
|
|
72
72
|
const { t } = useTranslation();
|
|
73
73
|
useEffect(() => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
74
|
+
if (loadingMetaStatus === 'success') {
|
|
75
|
+
const chain = blockchains.find(
|
|
76
|
+
(chain) => chain.name === config?.to?.blockchain
|
|
77
|
+
);
|
|
78
|
+
const token = tokens.find((t) =>
|
|
79
|
+
tokensAreEqual(t, config?.to?.token || null)
|
|
80
|
+
);
|
|
81
|
+
setToChain(chain || null);
|
|
82
|
+
setToToken(token || null);
|
|
83
|
+
}
|
|
84
|
+
}, [config?.to?.token, config?.to?.blockchain, loadingMetaStatus]);
|
|
83
85
|
|
|
84
86
|
useEffect(() => {
|
|
85
87
|
setInputAmount(config?.amount?.toString() || '');
|
|
86
88
|
}, [config?.amount]);
|
|
87
89
|
|
|
88
90
|
useEffect(() => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
if (loadingMetaStatus === 'success') {
|
|
92
|
+
const chain = blockchains.find(
|
|
93
|
+
(chain) => chain.name === config?.from?.blockchain
|
|
94
|
+
);
|
|
95
|
+
const token = tokens.find((t) =>
|
|
96
|
+
tokensAreEqual(t, config?.from?.token || null)
|
|
97
|
+
);
|
|
95
98
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
setFromChain(chain || null);
|
|
100
|
+
setFromToken(token || null);
|
|
101
|
+
}
|
|
102
|
+
}, [config?.from?.token, config?.from?.blockchain, loadingMetaStatus]);
|
|
99
103
|
|
|
100
104
|
useEffect(() => {
|
|
101
105
|
setAffiliateRef(config?.affiliateRef || null);
|
package/src/index.tsx
CHANGED
|
@@ -1,14 +1,144 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { SwapContainer } from '@rango-dev/ui';
|
|
2
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { AppRouter } from './components/AppRouter';
|
|
4
|
+
import { useMetaStore } from './store/meta';
|
|
5
|
+
import { Events, Provider } from '@rango-dev/wallets-core';
|
|
6
|
+
import { allProviders } from '@rango-dev/provider-all';
|
|
7
|
+
import { EventHandler } from '@rango-dev/wallets-core/dist/wallet';
|
|
8
|
+
import { Network, WalletType } from '@rango-dev/wallets-shared';
|
|
9
|
+
import {
|
|
10
|
+
prepareAccountsForWalletStore,
|
|
11
|
+
walletAndSupportedChainsNames,
|
|
12
|
+
} from './utils/wallets';
|
|
13
|
+
import { useWalletsStore } from './store/wallets';
|
|
14
|
+
import { Layout } from './components/Layout';
|
|
15
|
+
import { globalFont } from './globalStyles';
|
|
16
|
+
import { useTheme } from './hooks/useTheme';
|
|
17
|
+
import { isEvmBlockchain } from 'rango-sdk';
|
|
18
|
+
import {
|
|
19
|
+
WidgetTheme,
|
|
20
|
+
WidgetConfig,
|
|
21
|
+
WidgetColors,
|
|
22
|
+
BlockchainAndTokenConfig,
|
|
23
|
+
} from './types';
|
|
24
|
+
import useSelectLanguage from './hooks/useSelectLanguage';
|
|
25
|
+
import './i18n';
|
|
26
|
+
import QueueManager from './QueueManager';
|
|
27
|
+
import { useUiStore } from './store/ui';
|
|
28
|
+
import { navigationRoutes } from './constants/navigationRoutes';
|
|
29
|
+
import { initConfig } from './utils/configs';
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
WidgetConfig,
|
|
33
|
+
WalletType,
|
|
34
|
+
WidgetTheme,
|
|
35
|
+
WidgetColors,
|
|
36
|
+
BlockchainAndTokenConfig,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type WidgetProps = {
|
|
40
|
+
config?: WidgetConfig;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const Widget: React.FC<WidgetProps> = ({ config }) => {
|
|
44
|
+
globalFont(config?.theme?.fontFamily || 'Roboto');
|
|
45
|
+
|
|
46
|
+
const { activeTheme } = useTheme({ ...config?.theme });
|
|
47
|
+
const { blockchains } = useMetaStore.use.meta();
|
|
48
|
+
const disconnectWallet = useWalletsStore.use.disconnectWallet();
|
|
49
|
+
const connectWallet = useWalletsStore.use.connectWallet();
|
|
50
|
+
const { changeLanguage } = useSelectLanguage();
|
|
51
|
+
const clearConnectedWallet = useWalletsStore.use.clearConnectedWallet();
|
|
52
|
+
const [lastConnectedWalletWithNetwork, setLastConnectedWalletWithNetwork] =
|
|
53
|
+
useState<string>('');
|
|
54
|
+
const [disconnectedWallet, setDisconnectedWallet] = useState<WalletType>();
|
|
55
|
+
const currentPage = useUiStore.use.currentPage();
|
|
56
|
+
|
|
57
|
+
const evmBasedChainNames = blockchains
|
|
58
|
+
.filter(isEvmBlockchain)
|
|
59
|
+
.map((chain) => chain.name);
|
|
60
|
+
|
|
61
|
+
useMemo(() => {
|
|
62
|
+
if (config?.apiKey) {
|
|
63
|
+
initConfig({
|
|
64
|
+
API_KEY: config?.apiKey,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}, [config]);
|
|
68
|
+
|
|
69
|
+
const onUpdateState: EventHandler = (
|
|
70
|
+
type,
|
|
71
|
+
event,
|
|
72
|
+
value,
|
|
73
|
+
state,
|
|
74
|
+
supportedChains
|
|
75
|
+
) => {
|
|
76
|
+
if (event === Events.ACCOUNTS) {
|
|
77
|
+
if (value) {
|
|
78
|
+
const supportedChainNames: Network[] | null =
|
|
79
|
+
walletAndSupportedChainsNames(supportedChains);
|
|
80
|
+
const data = prepareAccountsForWalletStore(
|
|
81
|
+
type,
|
|
82
|
+
value,
|
|
83
|
+
evmBasedChainNames,
|
|
84
|
+
supportedChainNames
|
|
85
|
+
);
|
|
86
|
+
connectWallet(data);
|
|
87
|
+
} else {
|
|
88
|
+
disconnectWallet(type);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (event === Events.ACCOUNTS && state.connected) {
|
|
92
|
+
const key = `${type}-${state.network}-${value}`;
|
|
93
|
+
|
|
94
|
+
if (state.connected) {
|
|
95
|
+
setLastConnectedWalletWithNetwork(key);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (event === Events.NETWORK && state.network) {
|
|
100
|
+
const key = `${type}-${state.network}`;
|
|
101
|
+
setLastConnectedWalletWithNetwork(key);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
let providers = allProviders();
|
|
105
|
+
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
const wallets = config?.wallets;
|
|
108
|
+
clearConnectedWallet();
|
|
109
|
+
providers = !wallets
|
|
110
|
+
? allProviders()
|
|
111
|
+
: allProviders().filter((provider) => {
|
|
112
|
+
const type = provider.config.type;
|
|
113
|
+
return wallets.find((w) => w === type);
|
|
114
|
+
});
|
|
115
|
+
}, [config?.wallets]);
|
|
116
|
+
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
changeLanguage(config?.language || 'en');
|
|
119
|
+
}, [config?.language]);
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<Provider
|
|
123
|
+
allBlockChains={blockchains}
|
|
124
|
+
providers={providers}
|
|
125
|
+
onUpdateState={onUpdateState}
|
|
126
|
+
>
|
|
127
|
+
<div id="swap-container" className={activeTheme}>
|
|
128
|
+
<QueueManager>
|
|
129
|
+
<SwapContainer fixedHeight={currentPage !== navigationRoutes.home}>
|
|
130
|
+
<AppRouter
|
|
131
|
+
lastConnectedWallet={lastConnectedWalletWithNetwork}
|
|
132
|
+
disconnectedWallet={disconnectedWallet}
|
|
133
|
+
clearDisconnectedWallet={() => {
|
|
134
|
+
setDisconnectedWallet(undefined);
|
|
135
|
+
}}
|
|
136
|
+
>
|
|
137
|
+
<Layout config={config} />
|
|
138
|
+
</AppRouter>
|
|
139
|
+
</SwapContainer>
|
|
140
|
+
</QueueManager>
|
|
141
|
+
</div>
|
|
142
|
+
</Provider>
|
|
143
|
+
);
|
|
144
|
+
};
|
package/dist/App.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import './app.css';
|
|
3
|
-
import { WidgetConfig } from './types';
|
|
4
|
-
import './i18n';
|
|
5
|
-
export declare type WidgetProps = {
|
|
6
|
-
config?: WidgetConfig;
|
|
7
|
-
};
|
|
8
|
-
export declare function App({ config }: WidgetProps): JSX.Element;
|
|
9
|
-
//# sourceMappingURL=App.d.ts.map
|
package/dist/App.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["src/App.tsx"],"names":[],"mappings":";AAIA,OAAO,WAAW,CAAC;AAenB,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,QAAQ,CAAC;AAOhB,oBAAY,WAAW,GAAG;IACxB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,CAAC;AAEF,wBAAgB,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,WAAW,eA2F1C"}
|
package/dist/lib.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { WalletType } from '@rango-dev/wallets-shared';
|
|
3
|
-
import { WidgetTheme, WidgetConfig, WidgetColors, BlockchainAndTokenConfig } from './types';
|
|
4
|
-
import './i18n';
|
|
5
|
-
export { WidgetConfig, WalletType, WidgetTheme, WidgetColors, BlockchainAndTokenConfig, };
|
|
6
|
-
export declare type WidgetProps = {
|
|
7
|
-
config?: WidgetConfig;
|
|
8
|
-
};
|
|
9
|
-
export declare const Widget: React.FC<WidgetProps>;
|
|
10
|
-
//# sourceMappingURL=lib.d.ts.map
|
package/dist/lib.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["src/lib.tsx"],"names":[],"mappings":"AACA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAM5D,OAAO,EAAW,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAUhE,OAAO,EACL,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,wBAAwB,EACzB,MAAM,SAAS,CAAC;AAEjB,OAAO,QAAQ,CAAC;AAMhB,OAAO,EACL,YAAY,EACZ,UAAU,EACV,WAAW,EACX,YAAY,EACZ,wBAAwB,GACzB,CAAC;AAEF,oBAAY,WAAW,GAAG;IACxB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAqGxC,CAAC"}
|
package/src/App.tsx
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { SwapContainer } from '@rango-dev/ui';
|
|
2
|
-
import React, { useEffect, useMemo, useState } from 'react';
|
|
3
|
-
import { AppRouter } from './components/AppRouter';
|
|
4
|
-
import { useMetaStore } from './store/meta';
|
|
5
|
-
import './app.css';
|
|
6
|
-
import { Events, Provider } from '@rango-dev/wallets-core';
|
|
7
|
-
import { allProviders } from '@rango-dev/provider-all';
|
|
8
|
-
import { EventHandler } from '@rango-dev/wallets-core/dist/wallet';
|
|
9
|
-
import { Network, WalletType } from '@rango-dev/wallets-shared';
|
|
10
|
-
import {
|
|
11
|
-
prepareAccountsForWalletStore,
|
|
12
|
-
walletAndSupportedChainsNames,
|
|
13
|
-
} from './utils/wallets';
|
|
14
|
-
import { useWalletsStore } from './store/wallets';
|
|
15
|
-
import { Layout } from './components/Layout';
|
|
16
|
-
import { globalFont } from './globalStyles';
|
|
17
|
-
import { useTheme } from './hooks/useTheme';
|
|
18
|
-
import QueueManager from './QueueManager';
|
|
19
|
-
import { isEvmBlockchain } from 'rango-sdk';
|
|
20
|
-
import { WidgetConfig } from './types';
|
|
21
|
-
import './i18n';
|
|
22
|
-
import { useUiStore } from './store/ui';
|
|
23
|
-
import { navigationRoutes } from './constants/navigationRoutes';
|
|
24
|
-
import { initConfig } from './utils/configs';
|
|
25
|
-
|
|
26
|
-
const providers = allProviders();
|
|
27
|
-
|
|
28
|
-
export type WidgetProps = {
|
|
29
|
-
config?: WidgetConfig;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export function App({ config }: WidgetProps) {
|
|
33
|
-
globalFont(config?.theme?.fontFamily || 'Roboto');
|
|
34
|
-
const { activeTheme } = useTheme({ ...config?.theme });
|
|
35
|
-
useMemo(() => {
|
|
36
|
-
if (config?.apiKey) {
|
|
37
|
-
initConfig({
|
|
38
|
-
API_KEY: config?.apiKey,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}, [config]);
|
|
42
|
-
|
|
43
|
-
const { blockchains } = useMetaStore.use.meta();
|
|
44
|
-
const disconnectWallet = useWalletsStore.use.disconnectWallet();
|
|
45
|
-
const connectWallet = useWalletsStore.use.connectWallet();
|
|
46
|
-
const currentPage = useUiStore.use.currentPage();
|
|
47
|
-
|
|
48
|
-
const [lastConnectedWalletWithNetwork, setLastConnectedWalletWithNetwork] =
|
|
49
|
-
useState<string>('');
|
|
50
|
-
const [disconnectedWallet, setDisconnectedWallet] = useState<WalletType>();
|
|
51
|
-
|
|
52
|
-
const evmBasedChainNames = blockchains
|
|
53
|
-
.filter(isEvmBlockchain)
|
|
54
|
-
.map((chain) => chain.name);
|
|
55
|
-
|
|
56
|
-
const themeBackground = activeTheme?.colors?.background?.value;
|
|
57
|
-
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
document.body.style.background = themeBackground;
|
|
60
|
-
}, [themeBackground]);
|
|
61
|
-
|
|
62
|
-
const onUpdateState: EventHandler = (
|
|
63
|
-
type,
|
|
64
|
-
event,
|
|
65
|
-
value,
|
|
66
|
-
state,
|
|
67
|
-
supportedChains
|
|
68
|
-
) => {
|
|
69
|
-
if (event === Events.ACCOUNTS) {
|
|
70
|
-
if (value) {
|
|
71
|
-
const supportedChainNames: Network[] | null =
|
|
72
|
-
walletAndSupportedChainsNames(supportedChains);
|
|
73
|
-
const data = prepareAccountsForWalletStore(
|
|
74
|
-
type,
|
|
75
|
-
value,
|
|
76
|
-
evmBasedChainNames,
|
|
77
|
-
supportedChainNames
|
|
78
|
-
);
|
|
79
|
-
connectWallet(data);
|
|
80
|
-
} else {
|
|
81
|
-
disconnectWallet(type);
|
|
82
|
-
setDisconnectedWallet(type);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (event === Events.ACCOUNTS && state.connected) {
|
|
87
|
-
const key = `${type}-${state.network}-${value}`;
|
|
88
|
-
|
|
89
|
-
if (state.connected) {
|
|
90
|
-
setLastConnectedWalletWithNetwork(key);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (event === Events.NETWORK && state.network) {
|
|
95
|
-
const key = `${type}-${state.network}`;
|
|
96
|
-
setLastConnectedWalletWithNetwork(key);
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
return (
|
|
101
|
-
<Provider
|
|
102
|
-
allBlockChains={blockchains}
|
|
103
|
-
providers={providers}
|
|
104
|
-
onUpdateState={onUpdateState}
|
|
105
|
-
>
|
|
106
|
-
<div id="pageContainer" className={activeTheme}>
|
|
107
|
-
<QueueManager>
|
|
108
|
-
<SwapContainer fixedHeight={currentPage !== navigationRoutes.home}>
|
|
109
|
-
<AppRouter
|
|
110
|
-
lastConnectedWallet={lastConnectedWalletWithNetwork}
|
|
111
|
-
disconnectedWallet={disconnectedWallet}
|
|
112
|
-
clearDisconnectedWallet={() => {
|
|
113
|
-
setDisconnectedWallet(undefined);
|
|
114
|
-
}}
|
|
115
|
-
>
|
|
116
|
-
<Layout config={config} />
|
|
117
|
-
</AppRouter>
|
|
118
|
-
</SwapContainer>
|
|
119
|
-
</QueueManager>
|
|
120
|
-
</div>
|
|
121
|
-
</Provider>
|
|
122
|
-
);
|
|
123
|
-
}
|
package/src/app.css
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
@import url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap');
|
|
2
|
-
|
|
3
|
-
#app {
|
|
4
|
-
height: 100vh;
|
|
5
|
-
}
|
|
6
|
-
#pageContainer {
|
|
7
|
-
display: flex;
|
|
8
|
-
align-items: center;
|
|
9
|
-
justify-content: center;
|
|
10
|
-
height: 100%;
|
|
11
|
-
width: 100%;
|
|
12
|
-
}
|
package/src/lib.tsx
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { SwapContainer } from '@rango-dev/ui';
|
|
2
|
-
import React, { useEffect, useMemo, useState } from 'react';
|
|
3
|
-
import { AppRouter } from './components/AppRouter';
|
|
4
|
-
import { useMetaStore } from './store/meta';
|
|
5
|
-
import { Events, Provider } from '@rango-dev/wallets-core';
|
|
6
|
-
import { allProviders } from '@rango-dev/provider-all';
|
|
7
|
-
import { EventHandler } from '@rango-dev/wallets-core/dist/wallet';
|
|
8
|
-
import { Network, WalletType } from '@rango-dev/wallets-shared';
|
|
9
|
-
import {
|
|
10
|
-
prepareAccountsForWalletStore,
|
|
11
|
-
walletAndSupportedChainsNames,
|
|
12
|
-
} from './utils/wallets';
|
|
13
|
-
import { useWalletsStore } from './store/wallets';
|
|
14
|
-
import { Layout } from './components/Layout';
|
|
15
|
-
import { globalFont } from './globalStyles';
|
|
16
|
-
import { useTheme } from './hooks/useTheme';
|
|
17
|
-
import { isEvmBlockchain } from 'rango-sdk';
|
|
18
|
-
import {
|
|
19
|
-
WidgetTheme,
|
|
20
|
-
WidgetConfig,
|
|
21
|
-
WidgetColors,
|
|
22
|
-
BlockchainAndTokenConfig,
|
|
23
|
-
} from './types';
|
|
24
|
-
import useSelectLanguage from './hooks/useSelectLanguage';
|
|
25
|
-
import './i18n';
|
|
26
|
-
import QueueManager from './QueueManager';
|
|
27
|
-
import { useUiStore } from './store/ui';
|
|
28
|
-
import { navigationRoutes } from './constants/navigationRoutes';
|
|
29
|
-
import { initConfig } from './utils/configs';
|
|
30
|
-
|
|
31
|
-
export {
|
|
32
|
-
WidgetConfig,
|
|
33
|
-
WalletType,
|
|
34
|
-
WidgetTheme,
|
|
35
|
-
WidgetColors,
|
|
36
|
-
BlockchainAndTokenConfig,
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export type WidgetProps = {
|
|
40
|
-
config?: WidgetConfig;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export const Widget: React.FC<WidgetProps> = ({ config }) => {
|
|
44
|
-
globalFont(config?.theme?.fontFamily || 'Roboto');
|
|
45
|
-
|
|
46
|
-
const { activeTheme } = useTheme({ ...config?.theme });
|
|
47
|
-
const { blockchains } = useMetaStore.use.meta();
|
|
48
|
-
const disconnectWallet = useWalletsStore.use.disconnectWallet();
|
|
49
|
-
const connectWallet = useWalletsStore.use.connectWallet();
|
|
50
|
-
const { changeLanguage } = useSelectLanguage();
|
|
51
|
-
const clearConnectedWallet = useWalletsStore.use.clearConnectedWallet();
|
|
52
|
-
const [lastConnectedWalletWithNetwork, setLastConnectedWalletWithNetwork] =
|
|
53
|
-
useState<string>('');
|
|
54
|
-
const [disconnectedWallet, setDisconnectedWallet] = useState<WalletType>();
|
|
55
|
-
const currentPage = useUiStore.use.currentPage();
|
|
56
|
-
|
|
57
|
-
const evmBasedChainNames = blockchains
|
|
58
|
-
.filter(isEvmBlockchain)
|
|
59
|
-
.map((chain) => chain.name);
|
|
60
|
-
|
|
61
|
-
useMemo(() => {
|
|
62
|
-
if (config?.apiKey) {
|
|
63
|
-
initConfig({
|
|
64
|
-
API_KEY: config?.apiKey,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}, [config]);
|
|
68
|
-
|
|
69
|
-
const onUpdateState: EventHandler = (
|
|
70
|
-
type,
|
|
71
|
-
event,
|
|
72
|
-
value,
|
|
73
|
-
state,
|
|
74
|
-
supportedChains
|
|
75
|
-
) => {
|
|
76
|
-
if (event === Events.ACCOUNTS) {
|
|
77
|
-
if (value) {
|
|
78
|
-
const supportedChainNames: Network[] | null =
|
|
79
|
-
walletAndSupportedChainsNames(supportedChains);
|
|
80
|
-
const data = prepareAccountsForWalletStore(
|
|
81
|
-
type,
|
|
82
|
-
value,
|
|
83
|
-
evmBasedChainNames,
|
|
84
|
-
supportedChainNames
|
|
85
|
-
);
|
|
86
|
-
connectWallet(data);
|
|
87
|
-
} else {
|
|
88
|
-
disconnectWallet(type);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (event === Events.ACCOUNTS && state.connected) {
|
|
92
|
-
const key = `${type}-${state.network}-${value}`;
|
|
93
|
-
|
|
94
|
-
if (state.connected) {
|
|
95
|
-
setLastConnectedWalletWithNetwork(key);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (event === Events.NETWORK && state.network) {
|
|
100
|
-
const key = `${type}-${state.network}`;
|
|
101
|
-
setLastConnectedWalletWithNetwork(key);
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
let providers = allProviders();
|
|
105
|
-
|
|
106
|
-
useEffect(() => {
|
|
107
|
-
const wallets = config?.wallets;
|
|
108
|
-
clearConnectedWallet();
|
|
109
|
-
providers = !wallets
|
|
110
|
-
? allProviders()
|
|
111
|
-
: allProviders().filter((provider) => {
|
|
112
|
-
const type = provider.config.type;
|
|
113
|
-
return wallets.find((w) => w === type);
|
|
114
|
-
});
|
|
115
|
-
}, [config?.wallets]);
|
|
116
|
-
|
|
117
|
-
useEffect(() => {
|
|
118
|
-
changeLanguage(config?.language || 'en');
|
|
119
|
-
}, [config?.language]);
|
|
120
|
-
|
|
121
|
-
return (
|
|
122
|
-
<Provider
|
|
123
|
-
allBlockChains={blockchains}
|
|
124
|
-
providers={providers}
|
|
125
|
-
onUpdateState={onUpdateState}
|
|
126
|
-
>
|
|
127
|
-
<div className={activeTheme}>
|
|
128
|
-
<QueueManager>
|
|
129
|
-
<SwapContainer fixedHeight={currentPage !== navigationRoutes.home}>
|
|
130
|
-
<AppRouter
|
|
131
|
-
lastConnectedWallet={lastConnectedWalletWithNetwork}
|
|
132
|
-
disconnectedWallet={disconnectedWallet}
|
|
133
|
-
clearDisconnectedWallet={() => {
|
|
134
|
-
setDisconnectedWallet(undefined);
|
|
135
|
-
}}
|
|
136
|
-
>
|
|
137
|
-
<Layout config={config} />
|
|
138
|
-
</AppRouter>
|
|
139
|
-
</SwapContainer>
|
|
140
|
-
</QueueManager>
|
|
141
|
-
</div>
|
|
142
|
-
</Provider>
|
|
143
|
-
);
|
|
144
|
-
};
|