@rango-dev/widget-embedded 0.29.1-next.2 → 0.29.1-next.21
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/ConfirmWallets.styles.d.ts +6 -0
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.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/SearchInput/SearchInput.types.d.ts +2 -0
- package/dist/components/SearchInput/SearchInput.types.d.ts.map +1 -1
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/components/SwapDetailsModal/SwapDetailsModal.WalletState.d.ts.map +1 -1
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.d.ts +4 -0
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.d.ts.map +1 -0
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.styles.d.ts +325 -0
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.styles.d.ts.map +1 -0
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.types.d.ts +10 -0
- package/dist/components/WalletDerivationPathModal/WalletDerivationPathModal.types.d.ts.map +1 -0
- package/dist/components/WalletDerivationPathModal/index.d.ts +2 -0
- package/dist/components/WalletDerivationPathModal/index.d.ts.map +1 -0
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.d.ts +0 -2
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.d.ts.map +1 -1
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.types.d.ts +1 -1
- package/dist/components/WalletNamespacesModal/WalletNamespacesModal.types.d.ts.map +1 -1
- package/dist/constants/namespaces.d.ts +8 -0
- package/dist/constants/namespaces.d.ts.map +1 -0
- 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 +4 -3
- 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/types/wallets.d.ts +2 -1
- package/dist/types/wallets.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/utils/wallets.d.ts +4 -4
- package/dist/utils/wallets.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/ConfirmWalletsModal/WalletList.tsx +81 -14
- 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/SearchInput/SearchInput.types.ts +2 -0
- package/src/components/SwapDetails/SwapDetails.Placeholder.tsx +1 -1
- package/src/components/SwapDetails/SwapDetails.tsx +9 -10
- package/src/components/SwapDetailsModal/SwapDetailsModal.WalletState.tsx +77 -11
- package/src/components/TokenList/TokenList.tsx +5 -5
- package/src/components/WalletDerivationPathModal/WalletDerivationPathModal.styles.ts +17 -0
- package/src/components/WalletDerivationPathModal/WalletDerivationPathModal.tsx +154 -0
- package/src/components/WalletDerivationPathModal/WalletDerivationPathModal.types.tsx +10 -0
- package/src/components/WalletDerivationPathModal/index.ts +1 -0
- package/src/components/WalletNamespacesModal/WalletNamespacesModal.tsx +10 -15
- package/src/components/WalletNamespacesModal/WalletNamespacesModal.types.tsx +1 -1
- package/src/constants/namespaces.ts +62 -0
- 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 +14 -9
- 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 +99 -26
- 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/types/wallets.ts +2 -1
- 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/src/utils/wallets.ts +7 -5
- 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
|
@@ -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(() => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { WalletInfo } from '@rango-dev/ui';
|
|
2
|
-
import type {
|
|
2
|
+
import type { NamespaceData, WalletType } from '@rango-dev/wallets-shared';
|
|
3
3
|
import type { BlockchainMeta } from 'rango-sdk';
|
|
4
4
|
|
|
5
5
|
import { WalletState } from '@rango-dev/ui';
|
|
@@ -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,
|
|
@@ -73,7 +76,10 @@ export function useWalletList(params: Params) {
|
|
|
73
76
|
connectedWallet.chain === chain
|
|
74
77
|
);
|
|
75
78
|
|
|
76
|
-
const handleClick = async (
|
|
79
|
+
const handleClick = async (
|
|
80
|
+
type: WalletType,
|
|
81
|
+
namespaces?: NamespaceData[]
|
|
82
|
+
) => {
|
|
77
83
|
const wallet = state(type);
|
|
78
84
|
try {
|
|
79
85
|
if (error) {
|
|
@@ -82,18 +88,17 @@ export function useWalletList(params: Params) {
|
|
|
82
88
|
if (wallet.connected) {
|
|
83
89
|
await disconnect(type);
|
|
84
90
|
} else {
|
|
85
|
-
|
|
86
|
-
(w) => w.state === WalletState.CONNECTED
|
|
87
|
-
);
|
|
88
|
-
if (config?.multiWallets === false && atLeastOneWalletIsConnected) {
|
|
91
|
+
if (isSingleWalletActive(wallets, config.multiWallets)) {
|
|
89
92
|
return;
|
|
90
93
|
}
|
|
91
94
|
onBeforeConnect?.(type);
|
|
92
95
|
await connect(type, undefined, namespaces);
|
|
93
96
|
onConnect?.(type);
|
|
94
97
|
}
|
|
95
|
-
|
|
96
|
-
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
99
|
+
} catch (e: any) {
|
|
100
|
+
onError?.(e?.message);
|
|
101
|
+
setError('Error: ' + e?.message);
|
|
97
102
|
}
|
|
98
103
|
};
|
|
99
104
|
|
|
@@ -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
|
+
WalletInfoWithExtra,
|
|
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
|
+
WalletInfoWithExtra,
|
|
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 { WalletInfoWithExtra } from '../types';
|
|
1
2
|
import type { Namespace, WalletType } from '@rango-dev/wallets-shared';
|
|
2
3
|
|
|
3
4
|
import { i18n } from '@lingui/core';
|
|
@@ -13,24 +14,33 @@ import {
|
|
|
13
14
|
import React, { useState } from 'react';
|
|
14
15
|
|
|
15
16
|
import { Layout, PageContainer } from '../components/Layout';
|
|
17
|
+
import { WalletDerivationPathModal } from '../components/WalletDerivationPathModal';
|
|
16
18
|
import { WalletModal } from '../components/WalletModal';
|
|
17
19
|
import { WalletNamespacesModal } from '../components/WalletNamespacesModal';
|
|
18
20
|
import { useWalletList } from '../hooks/useWalletList';
|
|
19
21
|
import { useAppStore } from '../store/AppStore';
|
|
20
22
|
import { useUiStore } from '../store/ui';
|
|
21
|
-
import { getContainer } from '../utils/common';
|
|
23
|
+
import { getContainer, isSingleWalletActive } from '../utils/common';
|
|
22
24
|
import {
|
|
23
25
|
filterBlockchainsByWalletTypes,
|
|
24
26
|
filterWalletsByCategory,
|
|
25
27
|
} from '../utils/wallets';
|
|
26
28
|
|
|
27
29
|
interface NamespacesModalState {
|
|
30
|
+
open: boolean;
|
|
28
31
|
providerType: string;
|
|
29
32
|
providerImage: string;
|
|
30
33
|
availableNamespaces?: Namespace[];
|
|
31
34
|
singleNamespace?: boolean;
|
|
32
35
|
}
|
|
33
36
|
|
|
37
|
+
interface DerivationPathModalState {
|
|
38
|
+
open: boolean;
|
|
39
|
+
providerType: string;
|
|
40
|
+
providerImage: string;
|
|
41
|
+
namespace: Namespace;
|
|
42
|
+
}
|
|
43
|
+
|
|
34
44
|
const ListContainer = styled('div', {
|
|
35
45
|
display: 'flex',
|
|
36
46
|
justifyContent: 'center',
|
|
@@ -51,10 +61,13 @@ export function WalletsPage() {
|
|
|
51
61
|
const { fetchStatus: fetchMetaStatus } = useAppStore();
|
|
52
62
|
const [blockchainCategory, setBlockchainCategory] = useState<string>('ALL');
|
|
53
63
|
const blockchains = useAppStore().blockchains();
|
|
64
|
+
const { config } = useAppStore();
|
|
54
65
|
|
|
55
66
|
const [openModal, setOpenModal] = useState(false);
|
|
56
67
|
const [namespacesModalState, setNamespacesModalState] =
|
|
57
68
|
useState<NamespacesModalState | null>(null);
|
|
69
|
+
const [derivationPathModalState, setDerivationPathModalState] =
|
|
70
|
+
useState<DerivationPathModalState | null>(null);
|
|
58
71
|
const [selectedWalletType, setSelectedWalletType] = useState<WalletType>('');
|
|
59
72
|
let modalTimerId: ReturnType<typeof setTimeout> | null = null;
|
|
60
73
|
const isActiveTab = useUiStore.use.isActiveTab();
|
|
@@ -82,6 +95,24 @@ export function WalletsPage() {
|
|
|
82
95
|
setOpenModal(false);
|
|
83
96
|
};
|
|
84
97
|
|
|
98
|
+
const handleCloseNamespaceModal = () => {
|
|
99
|
+
if (namespacesModalState) {
|
|
100
|
+
setNamespacesModalState({
|
|
101
|
+
...namespacesModalState,
|
|
102
|
+
open: false,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const handleCloseDerivationPathModal = () => {
|
|
108
|
+
if (derivationPathModalState) {
|
|
109
|
+
setDerivationPathModalState({
|
|
110
|
+
...derivationPathModalState,
|
|
111
|
+
open: false,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
85
116
|
const selectedWallet = list.find(
|
|
86
117
|
(wallet) => wallet.type === selectedWalletType
|
|
87
118
|
);
|
|
@@ -95,6 +126,60 @@ export function WalletsPage() {
|
|
|
95
126
|
|
|
96
127
|
const filteredWallets = filterWalletsByCategory(list, blockchainCategory);
|
|
97
128
|
|
|
129
|
+
const handleWalletItemClick = (type: string, wallet: WalletInfoWithExtra) => {
|
|
130
|
+
if (isSingleWalletActive(list, config.multiWallets)) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (!!wallet.namespaces && wallet.state === WalletState.DISCONNECTED) {
|
|
135
|
+
setNamespacesModalState({
|
|
136
|
+
open: true,
|
|
137
|
+
providerType: type,
|
|
138
|
+
providerImage: wallet.image,
|
|
139
|
+
availableNamespaces: wallet.namespaces,
|
|
140
|
+
singleNamespace: wallet.singleNamespace,
|
|
141
|
+
});
|
|
142
|
+
} else {
|
|
143
|
+
void handleClick(type);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const handleConfirmNamespaces = (selectedNamespaces: Namespace[]) => {
|
|
148
|
+
const wallet = filteredWallets.find(
|
|
149
|
+
(wallet) => wallet.type === namespacesModalState?.providerType
|
|
150
|
+
);
|
|
151
|
+
if (
|
|
152
|
+
wallet?.singleNamespace && // Currently we support derivation path only for single namespace wallets
|
|
153
|
+
wallet?.needsDerivationPath &&
|
|
154
|
+
selectedNamespaces[0]
|
|
155
|
+
) {
|
|
156
|
+
setDerivationPathModalState({
|
|
157
|
+
open: true,
|
|
158
|
+
providerType: wallet.type,
|
|
159
|
+
providerImage: wallet.image,
|
|
160
|
+
namespace: selectedNamespaces[0],
|
|
161
|
+
});
|
|
162
|
+
} else {
|
|
163
|
+
void handleClick(
|
|
164
|
+
namespacesModalState?.providerType as string,
|
|
165
|
+
selectedNamespaces.map((namespace) => ({
|
|
166
|
+
namespace,
|
|
167
|
+
}))
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
handleCloseNamespaceModal();
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const handleDerivationPathConfirm = (derivationPath: string) => {
|
|
174
|
+
if (derivationPath && derivationPathModalState?.namespace) {
|
|
175
|
+
void handleClick(derivationPathModalState.providerType, [
|
|
176
|
+
{ namespace: derivationPathModalState.namespace, derivationPath },
|
|
177
|
+
]);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
handleCloseDerivationPathModal();
|
|
181
|
+
};
|
|
182
|
+
|
|
98
183
|
return (
|
|
99
184
|
<Layout
|
|
100
185
|
header={{
|
|
@@ -123,21 +208,7 @@ export function WalletsPage() {
|
|
|
123
208
|
key={key}
|
|
124
209
|
{...wallet}
|
|
125
210
|
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
|
-
}}
|
|
211
|
+
onClick={(type) => handleWalletItemClick(type, wallet)}
|
|
141
212
|
isLoading={fetchMetaStatus === 'loading'}
|
|
142
213
|
disabled={!isActiveTab}
|
|
143
214
|
/>
|
|
@@ -151,19 +222,21 @@ export function WalletsPage() {
|
|
|
151
222
|
error={error}
|
|
152
223
|
/>
|
|
153
224
|
<WalletNamespacesModal
|
|
154
|
-
open={!!namespacesModalState}
|
|
155
|
-
onClose={
|
|
156
|
-
onConfirm={
|
|
157
|
-
void handleClick(
|
|
158
|
-
namespacesModalState?.providerType as string,
|
|
159
|
-
namespaces
|
|
160
|
-
);
|
|
161
|
-
setNamespacesModalState(null);
|
|
162
|
-
}}
|
|
225
|
+
open={!!namespacesModalState?.open}
|
|
226
|
+
onClose={handleCloseNamespaceModal}
|
|
227
|
+
onConfirm={handleConfirmNamespaces}
|
|
163
228
|
image={namespacesModalState?.providerImage}
|
|
164
|
-
|
|
229
|
+
availableNamespaces={namespacesModalState?.availableNamespaces}
|
|
165
230
|
singleNamespace={namespacesModalState?.singleNamespace}
|
|
166
231
|
/>
|
|
232
|
+
<WalletDerivationPathModal
|
|
233
|
+
open={!!derivationPathModalState?.open}
|
|
234
|
+
selectedNamespace={derivationPathModalState?.namespace}
|
|
235
|
+
type={derivationPathModalState?.providerType}
|
|
236
|
+
image={derivationPathModalState?.providerImage}
|
|
237
|
+
onClose={handleCloseDerivationPathModal}
|
|
238
|
+
onConfirm={handleDerivationPathConfirm}
|
|
239
|
+
/>
|
|
167
240
|
</ListContainer>
|
|
168
241
|
</Container>
|
|
169
242
|
</Layout>
|
|
@@ -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
|
});
|