@rango-dev/widget-embedded 0.5.1-next.17 → 0.5.1-next.18
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/index.js +1 -1
- package/dist/index.js.map +3 -3
- package/dist/store/wallets.d.ts +2 -2
- package/dist/store/wallets.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/WidgetEvents.tsx +4 -4
- package/src/store/wallets.ts +39 -13
package/dist/store/wallets.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ interface WalletsStore {
|
|
|
27
27
|
initSelectedWallets: () => void;
|
|
28
28
|
setSelectedWallet: (wallet: SelectableWallet) => void;
|
|
29
29
|
clearConnectedWallet: () => void;
|
|
30
|
-
|
|
30
|
+
getWalletsDetails: (accounts: Wallet[], shouldRetry?: boolean) => void;
|
|
31
31
|
setCustomDestination: (customDestination: string) => void;
|
|
32
32
|
}
|
|
33
33
|
export declare const useWalletsStore: {
|
|
@@ -51,7 +51,7 @@ export declare const useWalletsStore: {
|
|
|
51
51
|
initSelectedWallets: () => () => void;
|
|
52
52
|
setSelectedWallet: () => (wallet: SelectableWallet) => void;
|
|
53
53
|
clearConnectedWallet: () => () => void;
|
|
54
|
-
|
|
54
|
+
getWalletsDetails: () => (accounts: Wallet[], shouldRetry?: boolean) => void;
|
|
55
55
|
setCustomDestination: () => (customDestination: string) => void;
|
|
56
56
|
};
|
|
57
57
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallets.d.ts","sourceRoot":"","sources":["../../src/store/wallets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAgBvD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;I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C;AAyBF,eAAO,MAAM,uBAAuB,UAAW,YAAY,YACA,CAAC"}
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@ import { useWalletsStore } from '../store/wallets';
|
|
|
10
10
|
|
|
11
11
|
export function WidgetEvents() {
|
|
12
12
|
const connectedWallets = useWalletsStore.use.connectedWallets();
|
|
13
|
-
const
|
|
13
|
+
const getWalletsDetails = useWalletsStore.use.getWalletsDetails();
|
|
14
14
|
|
|
15
15
|
const widgetEvents = useEvents();
|
|
16
16
|
|
|
@@ -20,7 +20,7 @@ export function WidgetEvents() {
|
|
|
20
20
|
const shouldRefetchBalance =
|
|
21
21
|
(event.type === StepEventType.TX_EXECUTION &&
|
|
22
22
|
event.status === StepExecutionEventStatus.TX_SENT &&
|
|
23
|
-
isApprovalTX(step)) ||
|
|
23
|
+
!isApprovalTX(step)) ||
|
|
24
24
|
event.type === StepEventType.SUCCEEDED;
|
|
25
25
|
|
|
26
26
|
if (shouldRefetchBalance) {
|
|
@@ -33,8 +33,8 @@ export function WidgetEvents() {
|
|
|
33
33
|
(wallet) => wallet.chain === step?.toBlockchain
|
|
34
34
|
);
|
|
35
35
|
|
|
36
|
-
fromAccount &&
|
|
37
|
-
toAccount &&
|
|
36
|
+
fromAccount && getWalletsDetails([fromAccount]);
|
|
37
|
+
toAccount && getWalletsDetails([toAccount]);
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
|
package/src/store/wallets.ts
CHANGED
|
@@ -45,7 +45,7 @@ interface WalletsStore {
|
|
|
45
45
|
initSelectedWallets: () => void;
|
|
46
46
|
setSelectedWallet: (wallet: SelectableWallet) => void;
|
|
47
47
|
clearConnectedWallet: () => void;
|
|
48
|
-
|
|
48
|
+
getWalletsDetails: (accounts: Wallet[], shouldRetry?: boolean) => void;
|
|
49
49
|
setCustomDestination: (customDestination: string) => void;
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -56,7 +56,7 @@ export const useWalletsStore = createSelectors(
|
|
|
56
56
|
selectedWallets: [],
|
|
57
57
|
customDestination: '',
|
|
58
58
|
connectWallet: (accounts) => {
|
|
59
|
-
const
|
|
59
|
+
const getWalletsDetails = get().getWalletsDetails;
|
|
60
60
|
set((state) => ({
|
|
61
61
|
connectedWallets: state.connectedWallets
|
|
62
62
|
.filter((wallet) => wallet.walletType !== accounts[0].walletType)
|
|
@@ -72,7 +72,7 @@ export const useWalletsStore = createSelectors(
|
|
|
72
72
|
}))
|
|
73
73
|
),
|
|
74
74
|
}));
|
|
75
|
-
accounts
|
|
75
|
+
getWalletsDetails(accounts);
|
|
76
76
|
},
|
|
77
77
|
disconnectWallet: (walletType) => {
|
|
78
78
|
set((state) => ({
|
|
@@ -131,26 +131,50 @@ export const useWalletsStore = createSelectors(
|
|
|
131
131
|
connectedWallets: [],
|
|
132
132
|
selectedWallets: [],
|
|
133
133
|
})),
|
|
134
|
-
|
|
135
|
-
const
|
|
134
|
+
getWalletsDetails: async (accounts, shouldRetry = true) => {
|
|
135
|
+
const getWalletsDetails = get().getWalletsDetails;
|
|
136
|
+
const { tokens } = useMetaStore.getState().meta;
|
|
136
137
|
set((state) => ({
|
|
137
138
|
connectedWallets: state.connectedWallets.map((wallet) => {
|
|
138
|
-
return
|
|
139
|
+
return accounts.find((account) =>
|
|
140
|
+
isAccountAndWalletMatched(account, wallet)
|
|
141
|
+
)
|
|
139
142
|
? { ...wallet, loading: true }
|
|
140
143
|
: wallet;
|
|
141
144
|
}),
|
|
142
145
|
}));
|
|
143
146
|
try {
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
147
|
+
const data = accounts.map(({ address, chain }) => ({
|
|
148
|
+
address,
|
|
149
|
+
blockchain: chain,
|
|
150
|
+
}));
|
|
151
|
+
const response = await httpService().getWalletsDetails(data);
|
|
152
|
+
const retrivedBalance = response.wallets;
|
|
148
153
|
if (retrivedBalance) {
|
|
149
154
|
set((state) => ({
|
|
150
155
|
connectedWallets: state.connectedWallets.map(
|
|
151
156
|
(connectedWallet) => {
|
|
152
|
-
|
|
153
|
-
|
|
157
|
+
const matchedAccount = accounts.find((account) =>
|
|
158
|
+
isAccountAndWalletMatched(account, connectedWallet)
|
|
159
|
+
);
|
|
160
|
+
const retrivedBalanceAccount = retrivedBalance.find(
|
|
161
|
+
(balance) =>
|
|
162
|
+
balance.address === connectedWallet.address &&
|
|
163
|
+
balance.blockChain === connectedWallet.chain
|
|
164
|
+
);
|
|
165
|
+
if (
|
|
166
|
+
retrivedBalanceAccount?.failed &&
|
|
167
|
+
matchedAccount &&
|
|
168
|
+
shouldRetry
|
|
169
|
+
) {
|
|
170
|
+
getWalletsDetails([matchedAccount], false);
|
|
171
|
+
}
|
|
172
|
+
return matchedAccount && retrivedBalanceAccount
|
|
173
|
+
? makeBalanceFor(
|
|
174
|
+
matchedAccount,
|
|
175
|
+
retrivedBalanceAccount,
|
|
176
|
+
tokens
|
|
177
|
+
)
|
|
154
178
|
: connectedWallet;
|
|
155
179
|
}
|
|
156
180
|
),
|
|
@@ -159,7 +183,9 @@ export const useWalletsStore = createSelectors(
|
|
|
159
183
|
} catch (error) {
|
|
160
184
|
set((state) => ({
|
|
161
185
|
connectedWallets: state.connectedWallets.map((balance) => {
|
|
162
|
-
return
|
|
186
|
+
return accounts.find((account) =>
|
|
187
|
+
isAccountAndWalletMatched(account, balance)
|
|
188
|
+
)
|
|
163
189
|
? resetConnectedWalletState(balance)
|
|
164
190
|
: balance;
|
|
165
191
|
}),
|