@rango-dev/widget-embedded 0.5.1-next.8 → 0.5.1-next.9
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/Widget.d.ts.map +1 -1
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/WidgetEvents.d.ts +2 -0
- package/dist/components/WidgetEvents.d.ts.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/package.json +3 -3
- package/src/QueueManager.tsx +0 -25
- package/src/Widget.tsx +2 -0
- package/src/components/AppRouter.tsx +0 -2
- package/src/components/WidgetEvents.tsx +46 -0
- package/src/index.ts +13 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/widget-embedded",
|
|
3
|
-
"version": "0.5.1-next.
|
|
3
|
+
"version": "0.5.1-next.9",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@rango-dev/provider-all": "^0.5.1-next.5",
|
|
21
21
|
"@rango-dev/queue-manager-core": "^0.5.1-next.1",
|
|
22
|
-
"@rango-dev/queue-manager-rango-preset": "^0.5.1-next.
|
|
22
|
+
"@rango-dev/queue-manager-rango-preset": "^0.5.1-next.9",
|
|
23
23
|
"@rango-dev/queue-manager-react": "^0.5.1-next.1",
|
|
24
|
-
"@rango-dev/ui": "^0.5.1-next.
|
|
24
|
+
"@rango-dev/ui": "^0.5.1-next.8",
|
|
25
25
|
"@rango-dev/wallets-core": "^0.5.1-next.5",
|
|
26
26
|
"@rango-dev/wallets-shared": "^0.5.1-next.10",
|
|
27
27
|
"bignumber.js": "^9.1.1",
|
package/src/QueueManager.tsx
CHANGED
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
makeQueueDefinition,
|
|
5
5
|
SwapQueueContext,
|
|
6
6
|
checkWaitingForNetworkChange,
|
|
7
|
-
SwapProgressNotification,
|
|
8
7
|
} from '@rango-dev/queue-manager-rango-preset';
|
|
9
8
|
import { useWallets } from '@rango-dev/wallets-core';
|
|
10
9
|
import {
|
|
@@ -33,7 +32,6 @@ function QueueManager(props: PropsWithChildren) {
|
|
|
33
32
|
API_KEY: getConfig('API_KEY'),
|
|
34
33
|
});
|
|
35
34
|
}, []);
|
|
36
|
-
const getOneOfWalletsDetails = useWalletsStore.use.getOneOfWalletsDetails();
|
|
37
35
|
|
|
38
36
|
const { blockchains } = useMetaStore.use.meta();
|
|
39
37
|
const connectedWallets = useWalletsStore.use.connectedWallets();
|
|
@@ -70,28 +68,6 @@ function QueueManager(props: PropsWithChildren) {
|
|
|
70
68
|
return walletAndSupportedChainsNames(supportedChains);
|
|
71
69
|
};
|
|
72
70
|
const allProviders = providers();
|
|
73
|
-
const notifier = (data: SwapProgressNotification) => {
|
|
74
|
-
const lastStep = data.swap?.steps[data.swap.steps.length - 1];
|
|
75
|
-
const outputAmount = data.step?.outputAmount || '';
|
|
76
|
-
const step = data.step || lastStep;
|
|
77
|
-
|
|
78
|
-
if (
|
|
79
|
-
data.eventType === 'task_completed' ||
|
|
80
|
-
(data.eventType === 'step_completed_with_output' &&
|
|
81
|
-
lastStep?.id !== data.step?.id) ||
|
|
82
|
-
!!outputAmount
|
|
83
|
-
) {
|
|
84
|
-
const fromAccount = connectedWallets.find(
|
|
85
|
-
(account) => account.chain === step?.fromBlockchain
|
|
86
|
-
);
|
|
87
|
-
const toAccount =
|
|
88
|
-
step?.fromBlockchain !== step?.toBlockchain &&
|
|
89
|
-
connectedWallets.find((wallet) => wallet.chain === step?.toBlockchain);
|
|
90
|
-
|
|
91
|
-
fromAccount && getOneOfWalletsDetails(fromAccount);
|
|
92
|
-
toAccount && getOneOfWalletsDetails(toAccount);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
71
|
|
|
96
72
|
const context: SwapQueueContext = {
|
|
97
73
|
meta: {
|
|
@@ -112,7 +88,6 @@ function QueueManager(props: PropsWithChildren) {
|
|
|
112
88
|
connect,
|
|
113
89
|
state,
|
|
114
90
|
isMobileWallet,
|
|
115
|
-
notifier,
|
|
116
91
|
};
|
|
117
92
|
|
|
118
93
|
return (
|
package/src/Widget.tsx
CHANGED
|
@@ -19,6 +19,7 @@ import { useUiStore } from './store/ui';
|
|
|
19
19
|
import { navigationRoutes } from './constants/navigationRoutes';
|
|
20
20
|
import { initConfig } from './utils/configs';
|
|
21
21
|
import { WidgetContext, WidgetWallets } from './Wallets';
|
|
22
|
+
import { WidgetEvents } from './components/WidgetEvents';
|
|
22
23
|
|
|
23
24
|
const MainContainer = styled('div', {
|
|
24
25
|
width: '100%',
|
|
@@ -62,6 +63,7 @@ export function Main(props: PropsWithChildren<WidgetProps>) {
|
|
|
62
63
|
return (
|
|
63
64
|
<MainContainer id="swap-container" className={activeTheme}>
|
|
64
65
|
<QueueManager>
|
|
66
|
+
<WidgetEvents />
|
|
65
67
|
<SwapContainer fixedHeight={currentPage !== navigationRoutes.home}>
|
|
66
68
|
<AppRouter
|
|
67
69
|
lastConnectedWallet={lastConnectedWalletWithNetwork}
|
|
@@ -27,8 +27,6 @@ export function AppRouter({
|
|
|
27
27
|
clearDisconnectedWallet: props.clearDisconnectedWallet,
|
|
28
28
|
disconnectedWallet: props.disconnectedWallet,
|
|
29
29
|
evmChains,
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
31
|
-
notifier: () => {},
|
|
32
30
|
canSwitchNetworkTo,
|
|
33
31
|
});
|
|
34
32
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
useEvents,
|
|
4
|
+
MainEvents,
|
|
5
|
+
StepEventType,
|
|
6
|
+
StepExecutionEventStatus,
|
|
7
|
+
isApprovalTX,
|
|
8
|
+
} from '@rango-dev/queue-manager-rango-preset';
|
|
9
|
+
import { useWalletsStore } from '../store/wallets';
|
|
10
|
+
|
|
11
|
+
export function WidgetEvents() {
|
|
12
|
+
const connectedWallets = useWalletsStore.use.connectedWallets();
|
|
13
|
+
const getOneOfWalletsDetails = useWalletsStore.use.getOneOfWalletsDetails();
|
|
14
|
+
|
|
15
|
+
const widgetEvents = useEvents();
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
widgetEvents.on(MainEvents.StepEvent, (widgetEvent) => {
|
|
19
|
+
const { event, step } = widgetEvent;
|
|
20
|
+
console.log({ event: widgetEvent });
|
|
21
|
+
const shouldRefetchBalance =
|
|
22
|
+
(event.type === StepEventType.TX_EXECUTION &&
|
|
23
|
+
event.status === StepExecutionEventStatus.TX_SENT &&
|
|
24
|
+
isApprovalTX(step)) ||
|
|
25
|
+
event.type === StepEventType.SUCCEEDED;
|
|
26
|
+
|
|
27
|
+
if (shouldRefetchBalance) {
|
|
28
|
+
const fromAccount = connectedWallets.find(
|
|
29
|
+
(account) => account.chain === step?.fromBlockchain
|
|
30
|
+
);
|
|
31
|
+
const toAccount =
|
|
32
|
+
step?.fromBlockchain !== step?.toBlockchain &&
|
|
33
|
+
connectedWallets.find(
|
|
34
|
+
(wallet) => wallet.chain === step?.toBlockchain
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
fromAccount && getOneOfWalletsDetails(fromAccount);
|
|
38
|
+
toAccount && getOneOfWalletsDetails(toAccount);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return () => widgetEvents.all.clear();
|
|
43
|
+
}, [widgetEvents, connectedWallets.length]);
|
|
44
|
+
|
|
45
|
+
return null;
|
|
46
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,14 @@ import { WidgetProps, Widget } from './Widget';
|
|
|
8
8
|
import { WalletType } from '@rango-dev/wallets-shared';
|
|
9
9
|
import { WidgetWallets } from './Wallets';
|
|
10
10
|
import { useWallets } from '@rango-dev/wallets-core';
|
|
11
|
+
import {
|
|
12
|
+
useEvents as useWidgetEvents,
|
|
13
|
+
MainEvents,
|
|
14
|
+
RouteEvent,
|
|
15
|
+
StepEvent,
|
|
16
|
+
Route,
|
|
17
|
+
Step,
|
|
18
|
+
} from '@rango-dev/queue-manager-rango-preset';
|
|
11
19
|
|
|
12
20
|
export type {
|
|
13
21
|
WidgetConfig,
|
|
@@ -16,6 +24,10 @@ export type {
|
|
|
16
24
|
WidgetColors,
|
|
17
25
|
BlockchainAndTokenConfig,
|
|
18
26
|
WidgetProps,
|
|
27
|
+
RouteEvent,
|
|
28
|
+
StepEvent,
|
|
29
|
+
Route,
|
|
30
|
+
Step,
|
|
19
31
|
};
|
|
20
32
|
export { Widget, WidgetWallets };
|
|
21
|
-
export { useWallets };
|
|
33
|
+
export { useWallets, useWidgetEvents, MainEvents };
|