@rango-dev/widget-embedded 0.29.1-next.8 → 0.30.0
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/SwapDetails/SwapDetails.helpers.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.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 +7 -2
- 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 -2
- 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 +9 -9
- 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 +24 -34
- 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.helpers.tsx +8 -10
- package/src/components/SwapDetails/SwapDetails.tsx +10 -11
- 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 +9 -6
- 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 +5 -5
- package/src/containers/Wallets/Wallets.tsx +1 -0
- 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 +12 -5
- 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 +85 -19
- package/src/services/eventEmitter.ts +11 -0
- package/src/store/notification.ts +3 -1
- package/src/store/quote.ts +70 -5
- package/src/store/slices/config.ts +4 -0
- package/src/store/slices/settings.ts +4 -1
- package/src/store/wallets.ts +194 -173
- package/src/types/config.ts +8 -4
- 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 +2 -2
- 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
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
import { useQuoteStore } from '../../store/quote';
|
|
18
18
|
import { useWalletsStore } from '../../store/wallets';
|
|
19
19
|
import { getContainer } from '../../utils/common';
|
|
20
|
-
import {
|
|
20
|
+
import { numberToString } from '../../utils/numbers';
|
|
21
21
|
import { getPriceImpact, getPriceImpactLevel } from '../../utils/quote';
|
|
22
22
|
import { canComputePriceImpact } from '../../utils/swap';
|
|
23
23
|
import { formatBalance, isFetchingBalance } from '../../utils/wallets';
|
|
@@ -40,7 +40,6 @@ export function Inputs(props: PropTypes) {
|
|
|
40
40
|
} = useQuoteStore();
|
|
41
41
|
const { connectedWallets, getBalanceFor } = useWalletsStore();
|
|
42
42
|
const fromTokenBalance = fromToken ? getBalanceFor(fromToken) : null;
|
|
43
|
-
|
|
44
43
|
const fromTokenFormattedBalance =
|
|
45
44
|
formatBalance(fromTokenBalance)?.amount ?? '0';
|
|
46
45
|
|
|
@@ -69,6 +68,7 @@ export function Inputs(props: PropTypes) {
|
|
|
69
68
|
!inputUsdValue || !outputUsdValue || !outputUsdValue.gt(0)
|
|
70
69
|
? null
|
|
71
70
|
: getPriceImpact(inputUsdValue.toString(), outputUsdValue.toString());
|
|
71
|
+
|
|
72
72
|
return (
|
|
73
73
|
<Container>
|
|
74
74
|
<FromContainer>
|
|
@@ -97,7 +97,7 @@ export function Inputs(props: PropTypes) {
|
|
|
97
97
|
),
|
|
98
98
|
realUsdValue: priceImpactInputCanNotBeComputed
|
|
99
99
|
? undefined
|
|
100
|
-
:
|
|
100
|
+
: inputUsdValue?.toString(),
|
|
101
101
|
error: priceImpactInputCanNotBeComputed
|
|
102
102
|
? errorMessages().unknownPriceError.impactTitle
|
|
103
103
|
: undefined,
|
|
@@ -144,10 +144,10 @@ export function Inputs(props: PropTypes) {
|
|
|
144
144
|
USD_VALUE_MIN_DECIMALS,
|
|
145
145
|
USD_VALUE_MAX_DECIMALS
|
|
146
146
|
),
|
|
147
|
-
realValue:
|
|
147
|
+
realValue: outputAmount?.toString(),
|
|
148
148
|
realUsdValue: priceImpactOutputCanNotBeComputed
|
|
149
149
|
? undefined
|
|
150
|
-
:
|
|
150
|
+
: outputUsdValue?.toString(),
|
|
151
151
|
error: priceImpactOutputCanNotBeComputed
|
|
152
152
|
? errorMessages().unknownPriceError.impactTitle
|
|
153
153
|
: undefined,
|
|
@@ -38,6 +38,7 @@ function Main(props: PropsWithChildren<PropTypes>) {
|
|
|
38
38
|
|
|
39
39
|
const walletOptions: ProvidersOptions = {
|
|
40
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(() => {
|
|
@@ -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';
|
|
@@ -28,6 +28,7 @@ interface Params {
|
|
|
28
28
|
chain?: string;
|
|
29
29
|
onBeforeConnect?: (walletType: string) => void;
|
|
30
30
|
onConnect?: (walletType: string) => void;
|
|
31
|
+
onError?: (error?: string) => void;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
/**
|
|
@@ -36,7 +37,7 @@ interface Params {
|
|
|
36
37
|
* you can use this list whenever you need to show the list of wallets and needed callbacks
|
|
37
38
|
*/
|
|
38
39
|
export function useWalletList(params: Params) {
|
|
39
|
-
const { chain, onBeforeConnect, onConnect } = params;
|
|
40
|
+
const { chain, onBeforeConnect, onConnect, onError } = params;
|
|
40
41
|
const { config } = useAppStore();
|
|
41
42
|
const { state, disconnect, getWalletInfo, connect } = useWallets();
|
|
42
43
|
const { connectedWallets } = useWalletsStore();
|
|
@@ -45,6 +46,7 @@ export function useWalletList(params: Params) {
|
|
|
45
46
|
/** It can be what has been set by widget config or as a fallback we use all the supported wallets by our library */
|
|
46
47
|
const listAvailableWalletTypes =
|
|
47
48
|
configWalletsToWalletName(config?.wallets, {
|
|
49
|
+
trezorManifest: config?.trezorManifest,
|
|
48
50
|
walletConnectProjectId: config?.walletConnectProjectId,
|
|
49
51
|
walletConnectListedDesktopWalletLink:
|
|
50
52
|
config.__UNSTABLE_OR_INTERNAL__?.walletConnectListedDesktopWalletLink,
|
|
@@ -74,7 +76,10 @@ export function useWalletList(params: Params) {
|
|
|
74
76
|
connectedWallet.chain === chain
|
|
75
77
|
);
|
|
76
78
|
|
|
77
|
-
const handleClick = async (
|
|
79
|
+
const handleClick = async (
|
|
80
|
+
type: WalletType,
|
|
81
|
+
namespaces?: NamespaceData[]
|
|
82
|
+
) => {
|
|
78
83
|
const wallet = state(type);
|
|
79
84
|
try {
|
|
80
85
|
if (error) {
|
|
@@ -90,8 +95,10 @@ export function useWalletList(params: Params) {
|
|
|
90
95
|
await connect(type, undefined, namespaces);
|
|
91
96
|
onConnect?.(type);
|
|
92
97
|
}
|
|
93
|
-
|
|
94
|
-
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
99
|
+
} catch (e: any) {
|
|
100
|
+
onError?.(e?.message);
|
|
101
|
+
setError('Error: ' + e?.message);
|
|
95
102
|
}
|
|
96
103
|
};
|
|
97
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,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WalletInfoWithExtra } from '../types';
|
|
2
2
|
import type { Namespace, WalletType } from '@rango-dev/wallets-shared';
|
|
3
3
|
|
|
4
4
|
import { i18n } from '@lingui/core';
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
import React, { useState } from 'react';
|
|
15
15
|
|
|
16
16
|
import { Layout, PageContainer } from '../components/Layout';
|
|
17
|
+
import { WalletDerivationPathModal } from '../components/WalletDerivationPathModal';
|
|
17
18
|
import { WalletModal } from '../components/WalletModal';
|
|
18
19
|
import { WalletNamespacesModal } from '../components/WalletNamespacesModal';
|
|
19
20
|
import { useWalletList } from '../hooks/useWalletList';
|
|
@@ -26,12 +27,20 @@ import {
|
|
|
26
27
|
} from '../utils/wallets';
|
|
27
28
|
|
|
28
29
|
interface NamespacesModalState {
|
|
30
|
+
open: boolean;
|
|
29
31
|
providerType: string;
|
|
30
32
|
providerImage: string;
|
|
31
33
|
availableNamespaces?: Namespace[];
|
|
32
34
|
singleNamespace?: boolean;
|
|
33
35
|
}
|
|
34
36
|
|
|
37
|
+
interface DerivationPathModalState {
|
|
38
|
+
open: boolean;
|
|
39
|
+
providerType: string;
|
|
40
|
+
providerImage: string;
|
|
41
|
+
namespace: Namespace;
|
|
42
|
+
}
|
|
43
|
+
|
|
35
44
|
const ListContainer = styled('div', {
|
|
36
45
|
display: 'flex',
|
|
37
46
|
justifyContent: 'center',
|
|
@@ -57,6 +66,8 @@ export function WalletsPage() {
|
|
|
57
66
|
const [openModal, setOpenModal] = useState(false);
|
|
58
67
|
const [namespacesModalState, setNamespacesModalState] =
|
|
59
68
|
useState<NamespacesModalState | null>(null);
|
|
69
|
+
const [derivationPathModalState, setDerivationPathModalState] =
|
|
70
|
+
useState<DerivationPathModalState | null>(null);
|
|
60
71
|
const [selectedWalletType, setSelectedWalletType] = useState<WalletType>('');
|
|
61
72
|
let modalTimerId: ReturnType<typeof setTimeout> | null = null;
|
|
62
73
|
const isActiveTab = useUiStore.use.isActiveTab();
|
|
@@ -84,6 +95,24 @@ export function WalletsPage() {
|
|
|
84
95
|
setOpenModal(false);
|
|
85
96
|
};
|
|
86
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
|
+
|
|
87
116
|
const selectedWallet = list.find(
|
|
88
117
|
(wallet) => wallet.type === selectedWalletType
|
|
89
118
|
);
|
|
@@ -97,15 +126,14 @@ export function WalletsPage() {
|
|
|
97
126
|
|
|
98
127
|
const filteredWallets = filterWalletsByCategory(list, blockchainCategory);
|
|
99
128
|
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
129
|
+
const handleWalletItemClick = (type: string, wallet: WalletInfoWithExtra) => {
|
|
130
|
+
if (isSingleWalletActive(list, config.multiWallets)) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
104
134
|
if (!!wallet.namespaces && wallet.state === WalletState.DISCONNECTED) {
|
|
105
|
-
if (isSingleWalletActive(list, config.multiWallets)) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
135
|
setNamespacesModalState({
|
|
136
|
+
open: true,
|
|
109
137
|
providerType: type,
|
|
110
138
|
providerImage: wallet.image,
|
|
111
139
|
availableNamespaces: wallet.namespaces,
|
|
@@ -116,6 +144,42 @@ export function WalletsPage() {
|
|
|
116
144
|
}
|
|
117
145
|
};
|
|
118
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
|
+
|
|
119
183
|
return (
|
|
120
184
|
<Layout
|
|
121
185
|
header={{
|
|
@@ -144,7 +208,7 @@ export function WalletsPage() {
|
|
|
144
208
|
key={key}
|
|
145
209
|
{...wallet}
|
|
146
210
|
container={getContainer()}
|
|
147
|
-
onClick={(type) =>
|
|
211
|
+
onClick={(type) => handleWalletItemClick(type, wallet)}
|
|
148
212
|
isLoading={fetchMetaStatus === 'loading'}
|
|
149
213
|
disabled={!isActiveTab}
|
|
150
214
|
/>
|
|
@@ -158,19 +222,21 @@ export function WalletsPage() {
|
|
|
158
222
|
error={error}
|
|
159
223
|
/>
|
|
160
224
|
<WalletNamespacesModal
|
|
161
|
-
open={!!namespacesModalState}
|
|
162
|
-
onClose={
|
|
163
|
-
onConfirm={
|
|
164
|
-
void handleClick(
|
|
165
|
-
namespacesModalState?.providerType as string,
|
|
166
|
-
namespaces
|
|
167
|
-
);
|
|
168
|
-
setNamespacesModalState(null);
|
|
169
|
-
}}
|
|
225
|
+
open={!!namespacesModalState?.open}
|
|
226
|
+
onClose={handleCloseNamespaceModal}
|
|
227
|
+
onConfirm={handleConfirmNamespaces}
|
|
170
228
|
image={namespacesModalState?.providerImage}
|
|
171
|
-
|
|
229
|
+
availableNamespaces={namespacesModalState?.availableNamespaces}
|
|
172
230
|
singleNamespace={namespacesModalState?.singleNamespace}
|
|
173
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
|
+
/>
|
|
174
240
|
</ListContainer>
|
|
175
241
|
</Container>
|
|
176
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();
|