@rango-dev/widget-embedded 0.29.1-next.2 → 0.29.1-next.20
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/QueueManager.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/NotificationContent/NotificationContent.d.ts.map +1 -1
- package/dist/components/Quote/Quote.d.ts.map +1 -1
- package/dist/components/Quote/Quote.styles.d.ts +1 -1
- package/dist/components/Quote/QuoteCostDetails.d.ts.map +1 -1
- package/dist/components/RefreshModal/RefreshModal.styles.d.ts +1 -1
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.d.ts +0 -2
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.d.ts.map +1 -1
- package/dist/constants/quote.d.ts +2 -1
- package/dist/constants/quote.d.ts.map +1 -1
- package/dist/constants/routing.d.ts +0 -1
- package/dist/constants/routing.d.ts.map +1 -1
- package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
- package/dist/containers/WidgetInfo/WidgetInfo.d.ts.map +1 -1
- package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts +3 -1
- package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts.map +1 -1
- package/dist/hooks/useBootstrap/useBootstrap.d.ts.map +1 -1
- package/dist/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.d.ts.map +1 -1
- package/dist/hooks/useSyncStoresWithConfig.d.ts.map +1 -1
- package/dist/hooks/useWalletList.d.ts +2 -1
- package/dist/hooks/useWalletList.d.ts.map +1 -1
- package/dist/hooks/useWalletProviders/index.d.ts +2 -0
- package/dist/hooks/useWalletProviders/index.d.ts.map +1 -0
- package/dist/hooks/{useWalletProviders.d.ts → useWalletProviders/useWalletProviders.d.ts} +2 -2
- package/dist/hooks/useWalletProviders/useWalletProviders.d.ts.map +1 -0
- package/dist/hooks/useWalletProviders/useWalletProviders.helpers.d.ts +3 -0
- package/dist/hooks/useWalletProviders/useWalletProviders.helpers.d.ts.map +1 -0
- package/dist/hooks/useWidgetEvents/index.d.ts +2 -0
- package/dist/hooks/useWidgetEvents/index.d.ts.map +1 -0
- package/dist/hooks/useWidgetEvents/useWidgetEvents.d.ts +3 -0
- package/dist/hooks/useWidgetEvents/useWidgetEvents.d.ts.map +1 -0
- package/dist/index.d.ts +16 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/services/eventEmitter.d.ts +4 -0
- package/dist/services/eventEmitter.d.ts.map +1 -0
- package/dist/store/notification.d.ts.map +1 -1
- package/dist/store/quote.d.ts +2 -1
- package/dist/store/quote.d.ts.map +1 -1
- package/dist/store/slices/config.d.ts.map +1 -1
- package/dist/store/slices/settings.d.ts.map +1 -1
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/config.d.ts +8 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/event.d.ts +68 -0
- package/dist/types/event.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/common.d.ts +2 -0
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/meta.d.ts +1 -0
- package/dist/utils/meta.d.ts.map +1 -1
- package/dist/utils/numbers.d.ts +0 -1
- package/dist/utils/numbers.d.ts.map +1 -1
- package/dist/utils/providers.d.ts +1 -0
- package/dist/utils/providers.d.ts.map +1 -1
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +7 -7
- package/src/QueueManager.tsx +4 -0
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +19 -9
- package/src/components/HistoryGroupedList/HistoryGroupedList.tsx +5 -5
- package/src/components/NotificationContent/NotificationContent.tsx +12 -113
- package/src/components/Quote/Quote.tsx +18 -25
- package/src/components/Quote/QuoteCostDetails.tsx +10 -9
- package/src/components/SwapDetails/SwapDetails.Placeholder.tsx +1 -1
- package/src/components/SwapDetails/SwapDetails.tsx +9 -10
- package/src/components/TokenList/TokenList.tsx +5 -5
- package/src/components/WalletNamespacesModal/WalletNamespacesModal.tsx +2 -10
- package/src/constants/quote.ts +11 -9
- package/src/constants/routing.ts +0 -2
- package/src/containers/Inputs/Inputs.tsx +4 -4
- package/src/containers/Wallets/Wallets.tsx +2 -1
- package/src/containers/WidgetInfo/WidgetInfo.tsx +3 -0
- package/src/containers/WidgetInfo/WidgetInfo.types.ts +3 -1
- package/src/hooks/useBootstrap/useBootstrap.ts +4 -0
- package/src/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.ts +8 -10
- package/src/hooks/useSyncStoresWithConfig.ts +3 -1
- package/src/hooks/useWalletList.ts +9 -7
- package/src/hooks/useWalletProviders/index.ts +1 -0
- package/src/hooks/useWalletProviders/useWalletProviders.helpers.ts +14 -0
- package/src/hooks/{useWalletProviders.ts → useWalletProviders/useWalletProviders.ts} +11 -5
- package/src/hooks/useWidgetEvents/index.ts +1 -0
- package/src/hooks/useWidgetEvents/useWidgetEvents.ts +9 -0
- package/src/index.ts +26 -2
- package/src/pages/WalletsPage.tsx +23 -16
- package/src/services/eventEmitter.ts +11 -0
- package/src/store/notification.ts +3 -1
- package/src/store/quote.ts +63 -1
- package/src/store/slices/config.ts +4 -0
- package/src/store/slices/settings.ts +6 -0
- package/src/store/wallets.ts +194 -173
- package/src/types/config.ts +9 -0
- package/src/types/event.ts +89 -0
- package/src/types/index.ts +1 -0
- package/src/utils/common.ts +12 -1
- package/src/utils/meta.ts +8 -0
- package/src/utils/numbers.ts +0 -12
- package/src/utils/providers.ts +4 -0
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts +0 -1559
- package/dist/components/NotificationContent/NotificationContent.styles.d.ts.map +0 -1
- package/dist/components/NotificationContent/NotificationNotFound.d.ts +0 -3
- package/dist/components/NotificationContent/NotificationNotFound.d.ts.map +0 -1
- package/dist/hooks/useWalletProviders.d.ts.map +0 -1
- package/src/components/NotificationContent/NotificationContent.styles.ts +0 -63
- package/src/components/NotificationContent/NotificationNotFound.tsx +0 -17
|
@@ -37,7 +37,8 @@ function Main(props: PropsWithChildren<PropTypes>) {
|
|
|
37
37
|
const config = useAppStore().config;
|
|
38
38
|
|
|
39
39
|
const walletOptions: ProvidersOptions = {
|
|
40
|
-
walletConnectProjectId:
|
|
40
|
+
walletConnectProjectId: config?.walletConnectProjectId,
|
|
41
|
+
trezorManifest: config?.trezorManifest,
|
|
41
42
|
walletConnectListedDesktopWalletLink:
|
|
42
43
|
props.config.__UNSTABLE_OR_INTERNAL__
|
|
43
44
|
?.walletConnectListedDesktopWalletLink,
|
|
@@ -34,6 +34,7 @@ export function WidgetInfo(props: React.PropsWithChildren) {
|
|
|
34
34
|
const loadingStatus = useAppStore().fetchStatus;
|
|
35
35
|
const resetLanguage = useLanguage().resetLanguage;
|
|
36
36
|
const notifications = useNotificationStore().getNotifications();
|
|
37
|
+
const clearNotifications = useNotificationStore().clearNotifications;
|
|
37
38
|
|
|
38
39
|
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
39
40
|
const value: WidgetInfoContextInterface = {
|
|
@@ -51,10 +52,12 @@ export function WidgetInfo(props: React.PropsWithChildren) {
|
|
|
51
52
|
tokens,
|
|
52
53
|
swappers,
|
|
53
54
|
loadingStatus,
|
|
55
|
+
findToken,
|
|
54
56
|
},
|
|
55
57
|
resetLanguage,
|
|
56
58
|
notifications: {
|
|
57
59
|
list: notifications,
|
|
60
|
+
clearAll: clearNotifications,
|
|
58
61
|
},
|
|
59
62
|
};
|
|
60
63
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { WidgetHistory } from './WidgetInfo.helpers';
|
|
2
|
-
import type { FetchStatus } from '../../store/slices/data';
|
|
2
|
+
import type { FetchStatus, FindToken } from '../../store/slices/data';
|
|
3
3
|
import type { ConnectedWallet } from '../../store/wallets';
|
|
4
4
|
import type { Wallet } from '../../types';
|
|
5
5
|
import type { Notification } from '../../types/notification';
|
|
@@ -20,9 +20,11 @@ export interface WidgetInfoContextInterface {
|
|
|
20
20
|
tokens: Token[];
|
|
21
21
|
swappers: SwapperMeta[];
|
|
22
22
|
loadingStatus: FetchStatus;
|
|
23
|
+
findToken: FindToken;
|
|
23
24
|
};
|
|
24
25
|
resetLanguage: () => void;
|
|
25
26
|
notifications: {
|
|
26
27
|
list: Notification[];
|
|
28
|
+
clearAll: () => void;
|
|
27
29
|
};
|
|
28
30
|
}
|
|
@@ -10,6 +10,7 @@ import { WidgetContext } from '../../containers/Wallets';
|
|
|
10
10
|
import { globalFont } from '../../globalStyles';
|
|
11
11
|
import { useAppStore } from '../../store/AppStore';
|
|
12
12
|
import { useNotificationStore } from '../../store/notification';
|
|
13
|
+
import { unsubscribeQuoteStore } from '../../store/quote';
|
|
13
14
|
import { tabManager } from '../../store/ui';
|
|
14
15
|
import { useFetchApiConfig } from '../useFetchApiConfig';
|
|
15
16
|
import { useForceAutoConnect } from '../useForceAutoConnect';
|
|
@@ -32,6 +33,9 @@ export function useBootstrap() {
|
|
|
32
33
|
|
|
33
34
|
const { fetchApiConfig } = useFetchApiConfig();
|
|
34
35
|
|
|
36
|
+
// Unsubscribe QuoteStore listeners
|
|
37
|
+
useEffect(() => () => unsubscribeQuoteStore(), []);
|
|
38
|
+
|
|
35
39
|
// At the moment, we only detect the disconnection of EVM wallets.
|
|
36
40
|
useQueueManager({
|
|
37
41
|
lastConnectedWallet: lastConnectedWalletWithNetwork,
|
|
@@ -2,14 +2,14 @@ import type { RouteEventData, StepEventData } from '../..';
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
isApprovalTX,
|
|
5
|
-
MainEvents,
|
|
6
5
|
RouteEventType,
|
|
7
6
|
StepEventType,
|
|
8
7
|
StepExecutionEventStatus,
|
|
9
|
-
|
|
8
|
+
WidgetEvents,
|
|
10
9
|
} from '@rango-dev/queue-manager-rango-preset';
|
|
11
10
|
import { useEffect } from 'react';
|
|
12
11
|
|
|
12
|
+
import { eventEmitter } from '../../services/eventEmitter';
|
|
13
13
|
import { useAppStore } from '../../store/AppStore';
|
|
14
14
|
import { useNotificationStore } from '../../store/notification';
|
|
15
15
|
import { useWalletsStore } from '../../store/wallets';
|
|
@@ -19,7 +19,6 @@ export function useSubscribeToWidgetEvents() {
|
|
|
19
19
|
const getWalletsDetails = useWalletsStore.use.getWalletsDetails();
|
|
20
20
|
const setNotification = useNotificationStore.use.setNotification();
|
|
21
21
|
const { findToken } = useAppStore();
|
|
22
|
-
const widgetEvents = useEvents();
|
|
23
22
|
|
|
24
23
|
useEffect(() => {
|
|
25
24
|
const handleStepEvent = (widgetEvent: StepEventData) => {
|
|
@@ -46,10 +45,9 @@ export function useSubscribeToWidgetEvents() {
|
|
|
46
45
|
|
|
47
46
|
setNotification(event, route);
|
|
48
47
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}, [widgetEvents, connectedWallets.length]);
|
|
48
|
+
eventEmitter.on(WidgetEvents.StepEvent, handleStepEvent);
|
|
49
|
+
return () => eventEmitter.off(WidgetEvents.StepEvent, handleStepEvent);
|
|
50
|
+
}, [eventEmitter, connectedWallets]);
|
|
53
51
|
|
|
54
52
|
useEffect(() => {
|
|
55
53
|
const handleRouteEvent = (widgetEvent: RouteEventData) => {
|
|
@@ -62,8 +60,8 @@ export function useSubscribeToWidgetEvents() {
|
|
|
62
60
|
setNotification(event, route);
|
|
63
61
|
}
|
|
64
62
|
};
|
|
65
|
-
|
|
63
|
+
eventEmitter.on(WidgetEvents.RouteEvent, handleRouteEvent);
|
|
66
64
|
|
|
67
|
-
return () =>
|
|
68
|
-
}, [
|
|
65
|
+
return () => eventEmitter.off(WidgetEvents.RouteEvent, handleRouteEvent);
|
|
66
|
+
}, [eventEmitter]);
|
|
69
67
|
}
|
|
@@ -42,7 +42,9 @@ export function useSyncStoresWithConfig() {
|
|
|
42
42
|
const prevConfigToBlockchain = useRef<string | undefined>(undefined);
|
|
43
43
|
|
|
44
44
|
useEffect(() => {
|
|
45
|
-
|
|
45
|
+
if (typeof config.amount !== 'undefined') {
|
|
46
|
+
setInputAmount(config.amount.toString());
|
|
47
|
+
}
|
|
46
48
|
}, [config?.amount]);
|
|
47
49
|
|
|
48
50
|
useEffect(() => {
|
|
@@ -13,6 +13,7 @@ import { useCallback, useEffect, useState } from 'react';
|
|
|
13
13
|
|
|
14
14
|
import { useAppStore } from '../store/AppStore';
|
|
15
15
|
import { useWalletsStore } from '../store/wallets';
|
|
16
|
+
import { isSingleWalletActive } from '../utils/common';
|
|
16
17
|
import { configWalletsToWalletName } from '../utils/providers';
|
|
17
18
|
import {
|
|
18
19
|
hashWalletsState,
|
|
@@ -27,6 +28,7 @@ interface Params {
|
|
|
27
28
|
chain?: string;
|
|
28
29
|
onBeforeConnect?: (walletType: string) => void;
|
|
29
30
|
onConnect?: (walletType: string) => void;
|
|
31
|
+
onError?: (error?: string) => void;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
/**
|
|
@@ -35,7 +37,7 @@ interface Params {
|
|
|
35
37
|
* you can use this list whenever you need to show the list of wallets and needed callbacks
|
|
36
38
|
*/
|
|
37
39
|
export function useWalletList(params: Params) {
|
|
38
|
-
const { chain, onBeforeConnect, onConnect } = params;
|
|
40
|
+
const { chain, onBeforeConnect, onConnect, onError } = params;
|
|
39
41
|
const { config } = useAppStore();
|
|
40
42
|
const { state, disconnect, getWalletInfo, connect } = useWallets();
|
|
41
43
|
const { connectedWallets } = useWalletsStore();
|
|
@@ -44,6 +46,7 @@ export function useWalletList(params: Params) {
|
|
|
44
46
|
/** It can be what has been set by widget config or as a fallback we use all the supported wallets by our library */
|
|
45
47
|
const listAvailableWalletTypes =
|
|
46
48
|
configWalletsToWalletName(config?.wallets, {
|
|
49
|
+
trezorManifest: config?.trezorManifest,
|
|
47
50
|
walletConnectProjectId: config?.walletConnectProjectId,
|
|
48
51
|
walletConnectListedDesktopWalletLink:
|
|
49
52
|
config.__UNSTABLE_OR_INTERNAL__?.walletConnectListedDesktopWalletLink,
|
|
@@ -82,18 +85,17 @@ export function useWalletList(params: Params) {
|
|
|
82
85
|
if (wallet.connected) {
|
|
83
86
|
await disconnect(type);
|
|
84
87
|
} else {
|
|
85
|
-
|
|
86
|
-
(w) => w.state === WalletState.CONNECTED
|
|
87
|
-
);
|
|
88
|
-
if (config?.multiWallets === false && atLeastOneWalletIsConnected) {
|
|
88
|
+
if (isSingleWalletActive(wallets, config.multiWallets)) {
|
|
89
89
|
return;
|
|
90
90
|
}
|
|
91
91
|
onBeforeConnect?.(type);
|
|
92
92
|
await connect(type, undefined, namespaces);
|
|
93
93
|
onConnect?.(type);
|
|
94
94
|
}
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
96
|
+
} catch (e: any) {
|
|
97
|
+
onError?.(e?.message);
|
|
98
|
+
setError('Error: ' + e?.message);
|
|
97
99
|
}
|
|
98
100
|
};
|
|
99
101
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useWalletProviders } from './useWalletProviders';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ProviderInterface } from '@rango-dev/wallets-react';
|
|
2
|
+
|
|
3
|
+
export function hashProviders(
|
|
4
|
+
providers: (string | ProviderInterface)[]
|
|
5
|
+
): string {
|
|
6
|
+
return providers
|
|
7
|
+
.map((provider) => {
|
|
8
|
+
if (typeof provider === 'string') {
|
|
9
|
+
return provider;
|
|
10
|
+
}
|
|
11
|
+
return provider.config.type;
|
|
12
|
+
})
|
|
13
|
+
.join('-');
|
|
14
|
+
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import type { WidgetConfig } from '
|
|
2
|
-
import type { ProvidersOptions } from '
|
|
1
|
+
import type { WidgetConfig } from '../../types';
|
|
2
|
+
import type { ProvidersOptions } from '../../utils/providers';
|
|
3
3
|
import type { ProviderInterface } from '@rango-dev/wallets-react';
|
|
4
4
|
|
|
5
5
|
import { useEffect } from 'react';
|
|
6
6
|
|
|
7
|
-
import { useWalletsStore } from '
|
|
8
|
-
import { matchAndGenerateProviders } from '
|
|
7
|
+
import { useWalletsStore } from '../../store/wallets';
|
|
8
|
+
import { matchAndGenerateProviders } from '../../utils/providers';
|
|
9
|
+
|
|
10
|
+
import { hashProviders } from './useWalletProviders.helpers';
|
|
9
11
|
|
|
10
12
|
export function useWalletProviders(
|
|
11
13
|
providers: WidgetConfig['wallets'],
|
|
@@ -20,7 +22,11 @@ export function useWalletProviders(
|
|
|
20
22
|
useEffect(() => {
|
|
21
23
|
clearConnectedWallet();
|
|
22
24
|
generateProviders = matchAndGenerateProviders(providers, options);
|
|
23
|
-
}, [
|
|
25
|
+
}, [
|
|
26
|
+
hashProviders(providers ?? []),
|
|
27
|
+
options?.walletConnectProjectId,
|
|
28
|
+
options?.walletConnectListedDesktopWalletLink,
|
|
29
|
+
]);
|
|
24
30
|
|
|
25
31
|
return {
|
|
26
32
|
providers: generateProviders,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useWidgetEvents } from './useWidgetEvents';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { WidgetEventEmitter } from '../../types';
|
|
2
|
+
|
|
3
|
+
import { eventEmitter } from '../../services/eventEmitter';
|
|
4
|
+
|
|
5
|
+
export function useWidgetEvents(): WidgetEventEmitter {
|
|
6
|
+
// To be exported for Dapps
|
|
7
|
+
const { on, off } = eventEmitter;
|
|
8
|
+
return { on, off };
|
|
9
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,10 @@ import type { WidgetProps } from './containers/Widget';
|
|
|
2
2
|
import type { ConnectedWallet } from './store/wallets';
|
|
3
3
|
import type {
|
|
4
4
|
BlockchainAndTokenConfig,
|
|
5
|
+
QuoteEventData,
|
|
5
6
|
Tokens,
|
|
7
|
+
WalletEventData,
|
|
8
|
+
WalletInfoWithNamespaces,
|
|
6
9
|
WidgetColors,
|
|
7
10
|
WidgetColorsKeys,
|
|
8
11
|
WidgetConfig,
|
|
@@ -43,12 +46,10 @@ import type { PendingSwap, PendingSwapStep } from 'rango-types';
|
|
|
43
46
|
|
|
44
47
|
import {
|
|
45
48
|
EventSeverity,
|
|
46
|
-
MainEvents,
|
|
47
49
|
RouteEventType,
|
|
48
50
|
StepEventType,
|
|
49
51
|
StepExecutionBlockedEventStatus,
|
|
50
52
|
StepExecutionEventStatus,
|
|
51
|
-
useEvents as useWidgetEvents,
|
|
52
53
|
} from '@rango-dev/queue-manager-rango-preset';
|
|
53
54
|
import {
|
|
54
55
|
readAccountAddress,
|
|
@@ -64,6 +65,15 @@ import { WidgetWallets } from './containers/Wallets';
|
|
|
64
65
|
import { Widget } from './containers/Widget';
|
|
65
66
|
import { useWidget } from './containers/WidgetInfo';
|
|
66
67
|
import { WidgetProvider } from './containers/WidgetProvider';
|
|
68
|
+
import { useWalletList } from './hooks/useWalletList';
|
|
69
|
+
import { useWidgetEvents } from './hooks/useWidgetEvents';
|
|
70
|
+
import { widgetEventEmitter } from './services/eventEmitter';
|
|
71
|
+
import {
|
|
72
|
+
WidgetEvents as MainEvents,
|
|
73
|
+
QuoteEventTypes,
|
|
74
|
+
WalletEventTypes,
|
|
75
|
+
WidgetEvents,
|
|
76
|
+
} from './types';
|
|
67
77
|
import { customizedThemeTokens } from './utils/ui';
|
|
68
78
|
|
|
69
79
|
export type {
|
|
@@ -96,6 +106,9 @@ export type {
|
|
|
96
106
|
ConnectedWallet,
|
|
97
107
|
Tokens,
|
|
98
108
|
WidgetVariant,
|
|
109
|
+
WalletEventData,
|
|
110
|
+
QuoteEventData,
|
|
111
|
+
WalletInfoWithNamespaces,
|
|
99
112
|
};
|
|
100
113
|
export {
|
|
101
114
|
Widget,
|
|
@@ -106,9 +119,20 @@ export {
|
|
|
106
119
|
WidgetProvider,
|
|
107
120
|
useWidget,
|
|
108
121
|
useWallets,
|
|
122
|
+
/**
|
|
123
|
+
* @deprecated Use `widgetEventEmitter` instead. This hook will be removed in future versions.
|
|
124
|
+
*/
|
|
109
125
|
useWidgetEvents,
|
|
126
|
+
useWalletList,
|
|
110
127
|
customizedThemeTokens,
|
|
128
|
+
widgetEventEmitter,
|
|
129
|
+
WidgetEvents,
|
|
130
|
+
/**
|
|
131
|
+
* @deprecated Use `WidgetEvents` instead. This enum will be removed in future versions.
|
|
132
|
+
*/
|
|
111
133
|
MainEvents,
|
|
134
|
+
QuoteEventTypes,
|
|
135
|
+
WalletEventTypes,
|
|
112
136
|
RouteEventType,
|
|
113
137
|
StepEventType,
|
|
114
138
|
StepExecutionEventStatus,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { WalletInfoWithNamespaces } from '../types';
|
|
1
2
|
import type { Namespace, WalletType } from '@rango-dev/wallets-shared';
|
|
2
3
|
|
|
3
4
|
import { i18n } from '@lingui/core';
|
|
@@ -18,7 +19,7 @@ import { WalletNamespacesModal } from '../components/WalletNamespacesModal';
|
|
|
18
19
|
import { useWalletList } from '../hooks/useWalletList';
|
|
19
20
|
import { useAppStore } from '../store/AppStore';
|
|
20
21
|
import { useUiStore } from '../store/ui';
|
|
21
|
-
import { getContainer } from '../utils/common';
|
|
22
|
+
import { getContainer, isSingleWalletActive } from '../utils/common';
|
|
22
23
|
import {
|
|
23
24
|
filterBlockchainsByWalletTypes,
|
|
24
25
|
filterWalletsByCategory,
|
|
@@ -51,6 +52,7 @@ export function WalletsPage() {
|
|
|
51
52
|
const { fetchStatus: fetchMetaStatus } = useAppStore();
|
|
52
53
|
const [blockchainCategory, setBlockchainCategory] = useState<string>('ALL');
|
|
53
54
|
const blockchains = useAppStore().blockchains();
|
|
55
|
+
const { config } = useAppStore();
|
|
54
56
|
|
|
55
57
|
const [openModal, setOpenModal] = useState(false);
|
|
56
58
|
const [namespacesModalState, setNamespacesModalState] =
|
|
@@ -95,6 +97,25 @@ export function WalletsPage() {
|
|
|
95
97
|
|
|
96
98
|
const filteredWallets = filterWalletsByCategory(list, blockchainCategory);
|
|
97
99
|
|
|
100
|
+
const handleWalletClick = (
|
|
101
|
+
type: string,
|
|
102
|
+
wallet: WalletInfoWithNamespaces
|
|
103
|
+
) => {
|
|
104
|
+
if (!!wallet.namespaces && wallet.state === WalletState.DISCONNECTED) {
|
|
105
|
+
if (isSingleWalletActive(list, config.multiWallets)) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
setNamespacesModalState({
|
|
109
|
+
providerType: type,
|
|
110
|
+
providerImage: wallet.image,
|
|
111
|
+
availableNamespaces: wallet.namespaces,
|
|
112
|
+
singleNamespace: wallet.singleNamespace,
|
|
113
|
+
});
|
|
114
|
+
} else {
|
|
115
|
+
void handleClick(type);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
98
119
|
return (
|
|
99
120
|
<Layout
|
|
100
121
|
header={{
|
|
@@ -123,21 +144,7 @@ export function WalletsPage() {
|
|
|
123
144
|
key={key}
|
|
124
145
|
{...wallet}
|
|
125
146
|
container={getContainer()}
|
|
126
|
-
onClick={(type) =>
|
|
127
|
-
if (
|
|
128
|
-
!!wallet.namespaces &&
|
|
129
|
-
wallet.state === WalletState.DISCONNECTED
|
|
130
|
-
) {
|
|
131
|
-
setNamespacesModalState({
|
|
132
|
-
providerType: type,
|
|
133
|
-
providerImage: wallet.image,
|
|
134
|
-
availableNamespaces: wallet.namespaces,
|
|
135
|
-
singleNamespace: wallet.singleNamespace,
|
|
136
|
-
});
|
|
137
|
-
} else {
|
|
138
|
-
void handleClick(type);
|
|
139
|
-
}
|
|
140
|
-
}}
|
|
147
|
+
onClick={(type) => handleWalletClick(type, wallet)}
|
|
141
148
|
isLoading={fetchMetaStatus === 'loading'}
|
|
142
149
|
disabled={!isActiveTab}
|
|
143
150
|
/>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Events, WidgetEventEmitter } from '../types';
|
|
2
|
+
|
|
3
|
+
import mitt from 'mitt';
|
|
4
|
+
|
|
5
|
+
export const eventEmitter = mitt<Events>();
|
|
6
|
+
|
|
7
|
+
// To be exported for Dapps
|
|
8
|
+
export const widgetEventEmitter: WidgetEventEmitter = {
|
|
9
|
+
on: eventEmitter.on,
|
|
10
|
+
off: eventEmitter.off,
|
|
11
|
+
};
|
|
@@ -66,7 +66,9 @@ export const useNotificationStore = createSelectors(
|
|
|
66
66
|
},
|
|
67
67
|
getNotifications: () => {
|
|
68
68
|
const { isSynced, notifications } = get();
|
|
69
|
-
return isSynced
|
|
69
|
+
return isSynced
|
|
70
|
+
? notifications.sort((a, b) => b.creationTime - a.creationTime)
|
|
71
|
+
: [];
|
|
70
72
|
},
|
|
71
73
|
syncNotifications: (swaps) => {
|
|
72
74
|
const { isSynced, notifications } = get();
|
package/src/store/quote.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { QuoteError, QuoteWarning, SelectedQuote, Wallet } from '../types';
|
|
2
1
|
import type {
|
|
3
2
|
BlockchainMeta,
|
|
4
3
|
MetaResponse,
|
|
@@ -12,6 +11,15 @@ import { create } from 'zustand';
|
|
|
12
11
|
import { subscribeWithSelector } from 'zustand/middleware';
|
|
13
12
|
|
|
14
13
|
import { ZERO } from '../constants/numbers';
|
|
14
|
+
import { eventEmitter } from '../services/eventEmitter';
|
|
15
|
+
import {
|
|
16
|
+
type QuoteError,
|
|
17
|
+
QuoteEventTypes,
|
|
18
|
+
type QuoteWarning,
|
|
19
|
+
type SelectedQuote,
|
|
20
|
+
type Wallet,
|
|
21
|
+
WidgetEvents,
|
|
22
|
+
} from '../types';
|
|
15
23
|
import { isPositiveNumber } from '../utils/numbers';
|
|
16
24
|
import { getQuoteToTokenUsdPrice } from '../utils/quote';
|
|
17
25
|
import { calcOutputUsdValue } from '../utils/swap';
|
|
@@ -289,3 +297,57 @@ export const useQuoteStore = createSelectors(
|
|
|
289
297
|
}))
|
|
290
298
|
)
|
|
291
299
|
);
|
|
300
|
+
|
|
301
|
+
export const unsubscribeQuoteStore = useQuoteStore.subscribe(
|
|
302
|
+
(selectedState, previousSelectedState) => {
|
|
303
|
+
if (
|
|
304
|
+
selectedState.fromBlockchain !== previousSelectedState.fromBlockchain ||
|
|
305
|
+
selectedState.fromToken !== previousSelectedState.fromToken ||
|
|
306
|
+
selectedState.toBlockchain !== previousSelectedState.toBlockchain ||
|
|
307
|
+
selectedState.toToken !== previousSelectedState.toToken ||
|
|
308
|
+
selectedState.inputAmount !== previousSelectedState.inputAmount
|
|
309
|
+
) {
|
|
310
|
+
// useEffect hook can not be used in Zustand subscribe
|
|
311
|
+
eventEmitter.emit(WidgetEvents.QuoteEvent, {
|
|
312
|
+
type: QuoteEventTypes.QUOTE_INPUT_UPDATE,
|
|
313
|
+
payload: {
|
|
314
|
+
fromBlockchain: selectedState.fromBlockchain?.name,
|
|
315
|
+
toBlockchain: selectedState.toBlockchain?.name,
|
|
316
|
+
fromToken: selectedState.fromToken
|
|
317
|
+
? {
|
|
318
|
+
symbol: selectedState.fromToken.symbol,
|
|
319
|
+
name: selectedState.fromToken.name,
|
|
320
|
+
address: selectedState.fromToken.address,
|
|
321
|
+
}
|
|
322
|
+
: undefined,
|
|
323
|
+
toToken: selectedState.toToken
|
|
324
|
+
? {
|
|
325
|
+
symbol: selectedState.toToken.symbol,
|
|
326
|
+
name: selectedState.toToken.name,
|
|
327
|
+
address: selectedState.toToken.address,
|
|
328
|
+
}
|
|
329
|
+
: undefined,
|
|
330
|
+
requestAmount: selectedState.inputAmount,
|
|
331
|
+
},
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (
|
|
336
|
+
selectedState.selectedQuote?.requestId !==
|
|
337
|
+
previousSelectedState.selectedQuote?.requestId
|
|
338
|
+
) {
|
|
339
|
+
eventEmitter.emit(WidgetEvents.QuoteEvent, {
|
|
340
|
+
type: QuoteEventTypes.QUOTE_OUTPUT_UPDATE,
|
|
341
|
+
payload: selectedState.selectedQuote
|
|
342
|
+
? {
|
|
343
|
+
requestAmount: selectedState.selectedQuote.requestAmount,
|
|
344
|
+
swaps: selectedState.selectedQuote.swaps,
|
|
345
|
+
outputAmount: selectedState.selectedQuote.outputAmount,
|
|
346
|
+
resultType: selectedState.selectedQuote.resultType,
|
|
347
|
+
tags: selectedState.selectedQuote.tags,
|
|
348
|
+
}
|
|
349
|
+
: null,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
);
|
|
@@ -9,6 +9,10 @@ export const DEFAULT_CONFIG: WidgetConfig = {
|
|
|
9
9
|
excludeLiquiditySources: true,
|
|
10
10
|
customDestination: true,
|
|
11
11
|
variant: 'default',
|
|
12
|
+
trezorManifest: {
|
|
13
|
+
appUrl: 'https://widget.rango.exchange/',
|
|
14
|
+
email: 'hi+trezorwidget@rango.exchange',
|
|
15
|
+
},
|
|
12
16
|
};
|
|
13
17
|
|
|
14
18
|
interface IframeConfigs {
|
|
@@ -159,6 +159,8 @@ export const createSettingsSlice: StateCreator<
|
|
|
159
159
|
const isLanguageHidden = isFeatureHidden('language', features);
|
|
160
160
|
const isLiquidityHidden = isFeatureHidden('liquiditySource', features);
|
|
161
161
|
const singleTheme = theme?.singleTheme;
|
|
162
|
+
const autoUpdateSettings =
|
|
163
|
+
nextConfig?.__UNSTABLE_OR_INTERNAL__?.autoUpdateSettings;
|
|
162
164
|
|
|
163
165
|
set({
|
|
164
166
|
...(isThemeHidden && { theme: nextConfig.theme?.mode || 'auto' }),
|
|
@@ -169,6 +171,10 @@ export const createSettingsSlice: StateCreator<
|
|
|
169
171
|
...(isLiquidityHidden && {
|
|
170
172
|
disabledLiquiditySources: nextConfig.liquiditySources || [],
|
|
171
173
|
}),
|
|
174
|
+
...(autoUpdateSettings && {
|
|
175
|
+
// For the time being, we have added the language; if more are needed later, we can add other parameters.
|
|
176
|
+
language: nextConfig.language || DEFAULT_LANGUAGE,
|
|
177
|
+
}),
|
|
172
178
|
});
|
|
173
179
|
},
|
|
174
180
|
});
|