@rango-dev/widget-embedded 0.64.4-next.0 → 0.64.4-next.10
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/containers/Wallets/Wallets.d.ts.map +1 -1
- package/dist/containers/Wallets/Wallets.helpers.d.ts.map +1 -1
- package/dist/containers/Wallets/useUpdates.d.ts.map +1 -1
- package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts +1 -1
- package/dist/hooks/useWalletList.d.ts.map +1 -1
- package/dist/hooks/useWalletProviders/useWalletProviders.d.ts +1 -1
- package/dist/index.d.ts +5 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +4 -4
- package/dist/store/slices/config.d.ts +3 -3
- package/dist/store/slices/config.d.ts.map +1 -1
- package/dist/store/slices/wallets.d.ts +1 -3
- package/dist/store/slices/wallets.d.ts.map +1 -1
- package/dist/types/event.d.ts +2 -30
- package/dist/types/event.d.ts.map +1 -1
- package/dist/utils/events.d.ts +1 -2
- package/dist/utils/events.d.ts.map +1 -1
- package/dist/utils/providers.d.ts +4 -6
- package/dist/utils/providers.d.ts.map +1 -1
- package/package.json +21 -11
- package/src/containers/Wallets/Wallets.helpers.ts +2 -5
- package/src/containers/Wallets/Wallets.tsx +2 -0
- package/src/containers/Wallets/useUpdates.ts +1 -3
- package/src/hooks/useStatefulConnect/useStatefulConnect.ts +1 -1
- package/src/hooks/useWalletList.ts +0 -36
- package/src/index.ts +6 -5
- package/src/store/slices/config.ts +27 -23
- package/src/store/slices/wallets.ts +3 -28
- package/src/types/event.ts +9 -42
- package/src/utils/events.ts +0 -9
- package/src/utils/providers.ts +11 -27
package/src/types/event.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { SelectedQuote } from './quote';
|
|
2
|
-
import type { Wallet } from './wallets';
|
|
3
2
|
import type {
|
|
4
3
|
RouteEventData,
|
|
5
4
|
StepEventData,
|
|
6
5
|
} from '@rango-dev/queue-manager-rango-preset';
|
|
6
|
+
import type { WalletEventData } from '@rango-dev/wallets-react';
|
|
7
|
+
|
|
8
|
+
import { WidgetEvents as QueueManagerEvents } from '@rango-dev/queue-manager-rango-preset';
|
|
9
|
+
import { WalletEventChannel } from '@rango-dev/wallets-react';
|
|
7
10
|
|
|
8
11
|
type EventData<
|
|
9
|
-
T extends QuoteEventTypes |
|
|
12
|
+
T extends QuoteEventTypes | UiEventTypes,
|
|
10
13
|
U extends Record<string, unknown> | null
|
|
11
14
|
> = { type: T; payload: U };
|
|
12
15
|
|
|
@@ -16,8 +19,6 @@ export type PreventableEventPayload<
|
|
|
16
19
|
preventDefault: () => void;
|
|
17
20
|
} & T;
|
|
18
21
|
|
|
19
|
-
type Account = Wallet;
|
|
20
|
-
|
|
21
22
|
export enum QuoteEventTypes {
|
|
22
23
|
QUOTE_INPUT_UPDATE = 'quoteInputUpdate',
|
|
23
24
|
QUOTE_OUTPUT_UPDATE = 'quoteOutputUpdate',
|
|
@@ -31,12 +32,6 @@ export enum QuoteEventTypes {
|
|
|
31
32
|
ROUTE_CHANGED = 'routeChanged',
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
export enum WalletEventTypes {
|
|
35
|
-
CONNECT = 'connect',
|
|
36
|
-
DISCONNECT = 'disconnect',
|
|
37
|
-
DETECTED = 'detected',
|
|
38
|
-
}
|
|
39
|
-
|
|
40
35
|
/**
|
|
41
36
|
* We use a prefix for interaction type and a name for defining the event name: INTERACTION_EVENT_NAME
|
|
42
37
|
* e.g. CLICK_X_BUTTON or NAVIGATE_WALLET_PAGE
|
|
@@ -72,24 +67,6 @@ export type QuoteUpdateEventPayload = Pick<
|
|
|
72
67
|
'requestAmount' | 'swaps' | 'outputAmount' | 'resultType' | 'tags'
|
|
73
68
|
> | null;
|
|
74
69
|
|
|
75
|
-
export type ConnectWalletEventPayload = {
|
|
76
|
-
walletType: string;
|
|
77
|
-
accounts: Account[];
|
|
78
|
-
/** Blockchain of the first connected account. */
|
|
79
|
-
chain: string | null;
|
|
80
|
-
/** wallet type (e.g. "metamask"). */
|
|
81
|
-
walletName: string;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export type DisconnectWalletEventPayload = {
|
|
85
|
-
walletType: string;
|
|
86
|
-
walletName: string;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
export type WalletDetectedEventPayload = {
|
|
90
|
-
walletName: string;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
70
|
export type ClickConnectWalletPayload = PreventableEventPayload;
|
|
94
71
|
|
|
95
72
|
/** Shared shape describing a route/quote, used by several swap events. */
|
|
@@ -217,11 +194,6 @@ export type QuoteEventData =
|
|
|
217
194
|
| EventData<QuoteEventTypes.ROUTE_FETCH_FAILED, RouteFetchFailedEventPayload>
|
|
218
195
|
| EventData<QuoteEventTypes.ROUTE_CHANGED, RouteChangedEventPayload>;
|
|
219
196
|
|
|
220
|
-
export type WalletEventData =
|
|
221
|
-
| EventData<WalletEventTypes.CONNECT, ConnectWalletEventPayload>
|
|
222
|
-
| EventData<WalletEventTypes.DISCONNECT, DisconnectWalletEventPayload>
|
|
223
|
-
| EventData<WalletEventTypes.DETECTED, WalletDetectedEventPayload>;
|
|
224
|
-
|
|
225
197
|
export type UiEventData =
|
|
226
198
|
| EventData<UiEventTypes.CLICK_CONNECT_WALLET, ClickConnectWalletPayload>
|
|
227
199
|
| EventData<UiEventTypes.TOKEN_SELECTED, TokenSelectedEventPayload>
|
|
@@ -248,17 +220,12 @@ export type UiEventData =
|
|
|
248
220
|
| EventData<UiEventTypes.SWAP_RETRIED, SwapRetriedEventPayload>
|
|
249
221
|
| EventData<UiEventTypes.SWAP_CANCELLED, SwapCancelledEventPayload>;
|
|
250
222
|
|
|
251
|
-
/**
|
|
252
|
-
* RouteEvent/StepEvent must match the queue-manager's `WidgetEvents` string
|
|
253
|
-
* values (`QueueManagerEvents`) so events route correctly. They're inlined as
|
|
254
|
-
* literals rather than referencing the other enum to keep this a pure string
|
|
255
|
-
* enum (a cross-enum reference makes `no-mixed-enums` read them as numeric).
|
|
256
|
-
*/
|
|
257
223
|
export enum WidgetEvents {
|
|
258
|
-
RouteEvent =
|
|
259
|
-
StepEvent =
|
|
224
|
+
RouteEvent = QueueManagerEvents.RouteEvent,
|
|
225
|
+
StepEvent = QueueManagerEvents.StepEvent,
|
|
260
226
|
QuoteEvent = 'quoteEvent',
|
|
261
|
-
|
|
227
|
+
// `isolatedModules` rejects a bare const reference in an enum initializer (TS18055).
|
|
228
|
+
WalletEvent = `${WalletEventChannel}`,
|
|
262
229
|
UiEvent = 'uiEvent',
|
|
263
230
|
}
|
|
264
231
|
|
package/src/utils/events.ts
CHANGED
|
@@ -4,8 +4,6 @@ import {
|
|
|
4
4
|
type QuoteEventData,
|
|
5
5
|
type UiEventData,
|
|
6
6
|
type UiEventTypes,
|
|
7
|
-
type WalletDetectedEventPayload,
|
|
8
|
-
WalletEventTypes,
|
|
9
7
|
WidgetEvents,
|
|
10
8
|
} from '../types';
|
|
11
9
|
|
|
@@ -41,10 +39,3 @@ export function emitPreventableEvent(
|
|
|
41
39
|
export function emitQuoteEvent(event: QuoteEventData): void {
|
|
42
40
|
eventEmitter.emit(WidgetEvents.QuoteEvent, event);
|
|
43
41
|
}
|
|
44
|
-
|
|
45
|
-
export function emitWalletDetected(payload: WalletDetectedEventPayload): void {
|
|
46
|
-
eventEmitter.emit(WidgetEvents.WalletEvent, {
|
|
47
|
-
type: WalletEventTypes.DETECTED,
|
|
48
|
-
payload,
|
|
49
|
-
});
|
|
50
|
-
}
|
package/src/utils/providers.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import type { WidgetConfig } from '../types';
|
|
2
2
|
|
|
3
3
|
import { Provider } from '@hub3js/core';
|
|
4
|
-
import {
|
|
5
|
-
defineVersions,
|
|
6
|
-
pickVersion,
|
|
7
|
-
type VersionedProviders,
|
|
8
|
-
} from '@hub3js/core/utils';
|
|
9
4
|
|
|
10
5
|
export interface ProvidersOptions {
|
|
11
6
|
walletConnectProjectId?: WidgetConfig['walletConnectProjectId'];
|
|
@@ -19,23 +14,23 @@ export interface ProvidersOptions {
|
|
|
19
14
|
/**
|
|
20
15
|
*
|
|
21
16
|
* Generate a list of providers by passing a provider name (e.g. metamask) or a custom hub `Provider`.
|
|
22
|
-
* @returns
|
|
17
|
+
* @returns Provider[] a list of hub Providers
|
|
23
18
|
*
|
|
24
19
|
*/
|
|
25
20
|
export function matchAndGenerateProviders({
|
|
26
21
|
allProviders,
|
|
27
22
|
configWallets,
|
|
28
23
|
}: {
|
|
29
|
-
allProviders:
|
|
24
|
+
allProviders: Provider[];
|
|
30
25
|
configWallets: WidgetConfig['wallets'];
|
|
31
26
|
options?: ProvidersOptions;
|
|
32
|
-
}):
|
|
27
|
+
}): Provider[] {
|
|
33
28
|
if (configWallets) {
|
|
34
29
|
/*
|
|
35
30
|
* If `wallets` is included in widget config,
|
|
36
31
|
* allProviders should be filtered based on wallets list
|
|
37
32
|
*/
|
|
38
|
-
const selectedProviders:
|
|
33
|
+
const selectedProviders: Provider[] = [];
|
|
39
34
|
|
|
40
35
|
configWallets.forEach((requestedWallet) => {
|
|
41
36
|
/*
|
|
@@ -45,7 +40,7 @@ export function matchAndGenerateProviders({
|
|
|
45
40
|
*/
|
|
46
41
|
if (typeof requestedWallet === 'string') {
|
|
47
42
|
const result = allProviders.find(
|
|
48
|
-
(provider) =>
|
|
43
|
+
(provider) => provider.id === requestedWallet
|
|
49
44
|
);
|
|
50
45
|
|
|
51
46
|
if (result) {
|
|
@@ -56,16 +51,11 @@ export function matchAndGenerateProviders({
|
|
|
56
51
|
`Couldn't find ${requestedWallet} provider. Please make sure you are passing the correct name.`
|
|
57
52
|
);
|
|
58
53
|
}
|
|
54
|
+
} else if (requestedWallet instanceof Provider) {
|
|
55
|
+
selectedProviders.push(requestedWallet);
|
|
59
56
|
} else {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
throw new Error(
|
|
63
|
-
`Legacy providers aren't supported anymore. Pass a hub 'Provider' instance in 'wallets' instead.`
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
selectedProviders.push(
|
|
68
|
-
defineVersions().version('1.0.0', requestedWallet).build()
|
|
57
|
+
throw new Error(
|
|
58
|
+
`Invalid item in widget config 'wallets': expected a wallet type string (e.g. 'metamask') or a hub 'Provider' instance, but received ${typeof requestedWallet}.`
|
|
69
59
|
);
|
|
70
60
|
}
|
|
71
61
|
});
|
|
@@ -76,12 +66,6 @@ export function matchAndGenerateProviders({
|
|
|
76
66
|
return allProviders;
|
|
77
67
|
}
|
|
78
68
|
|
|
79
|
-
export function
|
|
80
|
-
return
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function configWalletsToWalletName(
|
|
84
|
-
providers: VersionedProviders[]
|
|
85
|
-
): string[] {
|
|
86
|
-
return providers.map((provider) => pickProviderVersion(provider).id);
|
|
69
|
+
export function configWalletsToWalletName(providers: Provider[]): string[] {
|
|
70
|
+
return providers.map((provider) => provider.id);
|
|
87
71
|
}
|