@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
package/src/store/wallets.ts
CHANGED
|
@@ -6,7 +6,9 @@ import type { Token } from 'rango-sdk';
|
|
|
6
6
|
import { create } from 'zustand';
|
|
7
7
|
import { subscribeWithSelector } from 'zustand/middleware';
|
|
8
8
|
|
|
9
|
+
import { eventEmitter } from '../services/eventEmitter';
|
|
9
10
|
import { httpService } from '../services/httpService';
|
|
11
|
+
import { WalletEventTypes, WidgetEvents } from '../types';
|
|
10
12
|
import { createTokenHash } from '../utils/meta';
|
|
11
13
|
import {
|
|
12
14
|
isAccountAndWalletMatched,
|
|
@@ -54,156 +56,195 @@ interface WalletsStore {
|
|
|
54
56
|
|
|
55
57
|
export const useWalletsStore = createSelectors(
|
|
56
58
|
create<WalletsStore>()(
|
|
57
|
-
subscribeWithSelector((set, get) =>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
59
|
+
subscribeWithSelector((set, get) => {
|
|
60
|
+
return {
|
|
61
|
+
connectedWallets: [],
|
|
62
|
+
balances: {},
|
|
63
|
+
loading: false,
|
|
64
|
+
connectWallet: (accounts, findToken) => {
|
|
65
|
+
eventEmitter.emit(WidgetEvents.WalletEvent, {
|
|
66
|
+
type: WalletEventTypes.CONNECT,
|
|
67
|
+
payload: { walletType: accounts[0].walletType, accounts },
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const getWalletsDetails = get().getWalletsDetails;
|
|
71
|
+
set((state) => ({
|
|
72
|
+
loading: true,
|
|
73
|
+
connectedWallets: state.connectedWallets
|
|
74
|
+
.filter((wallet) => wallet.walletType !== accounts[0].walletType)
|
|
75
|
+
.concat(
|
|
76
|
+
accounts.map((account) => {
|
|
77
|
+
const shouldMarkWalletAsSelected =
|
|
78
|
+
!state.connectedWallets.some(
|
|
79
|
+
(connectedWallet) =>
|
|
80
|
+
connectedWallet.chain === account.chain &&
|
|
81
|
+
connectedWallet.selected &&
|
|
82
|
+
/**
|
|
83
|
+
* Sometimes, the connect function can be called multiple times for a particular wallet type when using the auto-connect feature.
|
|
84
|
+
* This check is there to make sure the chosen wallet doesn't end up unselected.
|
|
85
|
+
*/
|
|
86
|
+
connectedWallet.walletType !== account.walletType
|
|
87
|
+
);
|
|
88
|
+
return {
|
|
89
|
+
balances: [],
|
|
90
|
+
address: account.address,
|
|
91
|
+
chain: account.chain,
|
|
92
|
+
explorerUrl: null,
|
|
93
|
+
walletType: account.walletType,
|
|
94
|
+
selected: shouldMarkWalletAsSelected,
|
|
95
|
+
loading: true,
|
|
96
|
+
error: false,
|
|
97
|
+
};
|
|
98
|
+
})
|
|
99
|
+
),
|
|
100
|
+
}));
|
|
101
|
+
getWalletsDetails(accounts, findToken);
|
|
102
|
+
},
|
|
103
|
+
disconnectWallet: (walletType) => {
|
|
104
|
+
set((state) => {
|
|
105
|
+
if (
|
|
106
|
+
state.connectedWallets.find(
|
|
107
|
+
(wallet) => wallet.walletType === walletType
|
|
108
|
+
)
|
|
109
|
+
) {
|
|
110
|
+
eventEmitter.emit(WidgetEvents.WalletEvent, {
|
|
111
|
+
type: WalletEventTypes.DISCONNECT,
|
|
112
|
+
payload: { walletType },
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const selectedWallets = state.connectedWallets
|
|
117
|
+
.filter(
|
|
118
|
+
(connectedWallet) =>
|
|
119
|
+
connectedWallet.selected &&
|
|
120
|
+
connectedWallet.walletType !== walletType
|
|
121
|
+
)
|
|
122
|
+
.map((selectedWallet) => selectedWallet.chain);
|
|
123
|
+
|
|
124
|
+
const connectedWallets = state.connectedWallets
|
|
125
|
+
.filter(
|
|
126
|
+
(connectedWallet) => connectedWallet.walletType !== walletType
|
|
127
|
+
)
|
|
128
|
+
.map((connectedWallet) => {
|
|
129
|
+
const anyWalletSelectedForBlockchain = selectedWallets.includes(
|
|
130
|
+
connectedWallet.chain
|
|
78
131
|
);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
.map((connectedWallet) => {
|
|
109
|
-
const anyWalletSelectedForBlockchain = selectedWallets.includes(
|
|
110
|
-
connectedWallet.chain
|
|
132
|
+
if (anyWalletSelectedForBlockchain) {
|
|
133
|
+
return connectedWallet;
|
|
134
|
+
}
|
|
135
|
+
selectedWallets.push(connectedWallet.chain);
|
|
136
|
+
return { ...connectedWallet, selected: true };
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const balances = makeTokensBalance(connectedWallets);
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
balances,
|
|
143
|
+
connectedWallets,
|
|
144
|
+
};
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
selectWallets: (wallets) =>
|
|
148
|
+
set((state) => ({
|
|
149
|
+
connectedWallets: state.connectedWallets.map((connectedWallet) => {
|
|
150
|
+
const walletSelected = !!wallets.find(
|
|
151
|
+
(wallet) =>
|
|
152
|
+
wallet.chain === connectedWallet.chain &&
|
|
153
|
+
wallet.walletType !== connectedWallet.walletType &&
|
|
154
|
+
connectedWallet.selected
|
|
155
|
+
);
|
|
156
|
+
const walletNotSelected = !!wallets.find(
|
|
157
|
+
(wallet) =>
|
|
158
|
+
wallet.chain === connectedWallet.chain &&
|
|
159
|
+
wallet.walletType === connectedWallet.walletType &&
|
|
160
|
+
!connectedWallet.selected
|
|
111
161
|
);
|
|
112
|
-
if (
|
|
113
|
-
return connectedWallet;
|
|
162
|
+
if (walletSelected) {
|
|
163
|
+
return { ...connectedWallet, selected: false };
|
|
164
|
+
} else if (walletNotSelected) {
|
|
165
|
+
return { ...connectedWallet, selected: true };
|
|
114
166
|
}
|
|
115
|
-
selectedWallets.push(connectedWallet.chain);
|
|
116
|
-
return { ...connectedWallet, selected: true };
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
const balances = makeTokensBalance(connectedWallets);
|
|
120
|
-
|
|
121
|
-
return {
|
|
122
|
-
balances,
|
|
123
|
-
connectedWallets,
|
|
124
|
-
};
|
|
125
|
-
});
|
|
126
|
-
},
|
|
127
|
-
selectWallets: (wallets) =>
|
|
128
|
-
set((state) => ({
|
|
129
|
-
connectedWallets: state.connectedWallets.map((connectedWallet) => {
|
|
130
|
-
const walletSelected = !!wallets.find(
|
|
131
|
-
(wallet) =>
|
|
132
|
-
wallet.chain === connectedWallet.chain &&
|
|
133
|
-
wallet.walletType !== connectedWallet.walletType &&
|
|
134
|
-
connectedWallet.selected
|
|
135
|
-
);
|
|
136
|
-
const walletNotSelected = !!wallets.find(
|
|
137
|
-
(wallet) =>
|
|
138
|
-
wallet.chain === connectedWallet.chain &&
|
|
139
|
-
wallet.walletType === connectedWallet.walletType &&
|
|
140
|
-
!connectedWallet.selected
|
|
141
|
-
);
|
|
142
|
-
if (walletSelected) {
|
|
143
|
-
return { ...connectedWallet, selected: false };
|
|
144
|
-
} else if (walletNotSelected) {
|
|
145
|
-
return { ...connectedWallet, selected: true };
|
|
146
|
-
}
|
|
147
167
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}));
|
|
168
|
-
try {
|
|
169
|
-
const data = accounts.map(({ address, chain }) => ({
|
|
170
|
-
address,
|
|
171
|
-
blockchain: chain,
|
|
168
|
+
return connectedWallet;
|
|
169
|
+
}),
|
|
170
|
+
})),
|
|
171
|
+
clearConnectedWallet: () =>
|
|
172
|
+
set(() => ({
|
|
173
|
+
connectedWallets: [],
|
|
174
|
+
selectedWallets: [],
|
|
175
|
+
})),
|
|
176
|
+
getWalletsDetails: async (accounts, findToken, shouldRetry = true) => {
|
|
177
|
+
const getWalletsDetails = get().getWalletsDetails;
|
|
178
|
+
set((state) => ({
|
|
179
|
+
loading: true,
|
|
180
|
+
connectedWallets: state.connectedWallets.map((wallet) => {
|
|
181
|
+
return accounts.find((account) =>
|
|
182
|
+
isAccountAndWalletMatched(account, wallet)
|
|
183
|
+
)
|
|
184
|
+
? { ...wallet, loading: true }
|
|
185
|
+
: wallet;
|
|
186
|
+
}),
|
|
172
187
|
}));
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
188
|
+
try {
|
|
189
|
+
const data = accounts.map(({ address, chain }) => ({
|
|
190
|
+
address,
|
|
191
|
+
blockchain: chain,
|
|
192
|
+
}));
|
|
193
|
+
const response = await httpService().getWalletsDetails(data);
|
|
194
|
+
const retrievedBalance = response.wallets;
|
|
195
|
+
if (retrievedBalance) {
|
|
196
|
+
set((state) => {
|
|
197
|
+
const connectedWallets = state.connectedWallets.map(
|
|
198
|
+
(connectedWallet) => {
|
|
199
|
+
const matchedAccount = accounts.find((account) =>
|
|
200
|
+
isAccountAndWalletMatched(account, connectedWallet)
|
|
201
|
+
);
|
|
202
|
+
const retrievedBalanceAccount = retrievedBalance.find(
|
|
203
|
+
(balance) =>
|
|
204
|
+
balance.address === connectedWallet.address &&
|
|
205
|
+
balance.blockChain === connectedWallet.chain
|
|
206
|
+
);
|
|
207
|
+
if (
|
|
208
|
+
retrievedBalanceAccount?.failed &&
|
|
209
|
+
matchedAccount &&
|
|
210
|
+
shouldRetry
|
|
211
|
+
) {
|
|
212
|
+
getWalletsDetails([matchedAccount], findToken, false);
|
|
213
|
+
}
|
|
214
|
+
return matchedAccount && retrievedBalanceAccount
|
|
215
|
+
? {
|
|
216
|
+
...connectedWallet,
|
|
217
|
+
explorerUrl: retrievedBalanceAccount.explorerUrl,
|
|
218
|
+
balances: makeBalanceFor(
|
|
219
|
+
retrievedBalanceAccount,
|
|
220
|
+
findToken
|
|
221
|
+
),
|
|
222
|
+
loading: false,
|
|
223
|
+
}
|
|
224
|
+
: connectedWallet;
|
|
193
225
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
const balances = makeTokensBalance(connectedWallets);
|
|
229
|
+
|
|
230
|
+
return {
|
|
231
|
+
loading: false,
|
|
232
|
+
balances,
|
|
233
|
+
connectedWallets,
|
|
234
|
+
};
|
|
235
|
+
});
|
|
236
|
+
} else {
|
|
237
|
+
throw new Error('Wallet not found');
|
|
238
|
+
}
|
|
239
|
+
} catch (error) {
|
|
240
|
+
set((state) => {
|
|
241
|
+
const connectedWallets = state.connectedWallets.map((balance) => {
|
|
242
|
+
return accounts.find((account) =>
|
|
243
|
+
isAccountAndWalletMatched(account, balance)
|
|
244
|
+
)
|
|
245
|
+
? resetConnectedWalletState(balance)
|
|
246
|
+
: balance;
|
|
247
|
+
});
|
|
207
248
|
|
|
208
249
|
const balances = makeTokensBalance(connectedWallets);
|
|
209
250
|
|
|
@@ -213,35 +254,15 @@ export const useWalletsStore = createSelectors(
|
|
|
213
254
|
connectedWallets,
|
|
214
255
|
};
|
|
215
256
|
});
|
|
216
|
-
} else {
|
|
217
|
-
throw new Error('Wallet not found');
|
|
218
257
|
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const balances = makeTokensBalance(connectedWallets);
|
|
230
|
-
|
|
231
|
-
return {
|
|
232
|
-
loading: false,
|
|
233
|
-
balances,
|
|
234
|
-
connectedWallets,
|
|
235
|
-
};
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
getBalanceFor: (token) => {
|
|
240
|
-
const { balances } = get();
|
|
241
|
-
const tokenHash = createTokenHash(token);
|
|
242
|
-
const balance = balances[tokenHash];
|
|
243
|
-
return balance ?? null;
|
|
244
|
-
},
|
|
245
|
-
}))
|
|
258
|
+
},
|
|
259
|
+
getBalanceFor: (token) => {
|
|
260
|
+
const { balances } = get();
|
|
261
|
+
const tokenHash = createTokenHash(token);
|
|
262
|
+
const balance = balances[tokenHash];
|
|
263
|
+
return balance ?? null;
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
})
|
|
246
267
|
)
|
|
247
268
|
);
|
package/src/types/config.ts
CHANGED
|
@@ -145,6 +145,11 @@ export type Features = Partial<
|
|
|
145
145
|
> &
|
|
146
146
|
Partial<Record<'experimentalRoute', 'disabled' | 'enabled'>>;
|
|
147
147
|
|
|
148
|
+
export type TrezorManifest = {
|
|
149
|
+
appUrl: string;
|
|
150
|
+
email: string;
|
|
151
|
+
};
|
|
152
|
+
|
|
148
153
|
/**
|
|
149
154
|
* The type WidgetConfig defines the configuration options for a widget, including API key, affiliate
|
|
150
155
|
* reference, amount, blockchain and token configurations, liquidity sources, wallet types, language,
|
|
@@ -158,6 +163,8 @@ export type Features = Partial<
|
|
|
158
163
|
* @property {BlockchainAndTokenConfig} from - The `from` property is an optional property of type
|
|
159
164
|
* `BlockchainAndTokenConfig` that specifies the default blockchain and token from which the user wants to
|
|
160
165
|
* exchange.It can also used to limit source swap blockchains/tokens to some limited ones.
|
|
166
|
+
* @property {TrezorManifest} trezorManifest - Trezor Connect Manifest requires that you,
|
|
167
|
+
* as a Trezor Connect integrator,share your e-mail and application url.
|
|
161
168
|
* @property {BlockchainAndTokenConfig} to - The "to" property is an optional property of type
|
|
162
169
|
* "BlockchainAndTokenConfig" that specifies the default blockchain and token to which the user wants to
|
|
163
170
|
* exchange.It can also used to limit destination swap blockchains/tokens to some limited ones.
|
|
@@ -203,6 +210,7 @@ export type WidgetConfig = {
|
|
|
203
210
|
apiUrl?: string;
|
|
204
211
|
title?: string;
|
|
205
212
|
walletConnectProjectId?: string;
|
|
213
|
+
trezorManifest?: TrezorManifest;
|
|
206
214
|
affiliate?: WidgetAffiliate;
|
|
207
215
|
amount?: number;
|
|
208
216
|
from?: BlockchainAndTokenConfig;
|
|
@@ -223,5 +231,6 @@ export type WidgetConfig = {
|
|
|
223
231
|
// These are likely to change or remove at anytime. Please use with a caution.
|
|
224
232
|
__UNSTABLE_OR_INTERNAL__?: {
|
|
225
233
|
walletConnectListedDesktopWalletLink?: string;
|
|
234
|
+
autoUpdateSettings?: boolean; // If true, settings will be updated automatically based on the configuration.
|
|
226
235
|
};
|
|
227
236
|
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { SelectedQuote } from './quote';
|
|
2
|
+
import type { Wallet } from './wallets';
|
|
3
|
+
import type {
|
|
4
|
+
RouteEventData,
|
|
5
|
+
StepEventData,
|
|
6
|
+
} from '@rango-dev/queue-manager-rango-preset';
|
|
7
|
+
|
|
8
|
+
import { WidgetEvents as QueueManagerEvents } from '@rango-dev/queue-manager-rango-preset';
|
|
9
|
+
|
|
10
|
+
type Account = Wallet;
|
|
11
|
+
|
|
12
|
+
export enum QuoteEventTypes {
|
|
13
|
+
QUOTE_INPUT_UPDATE = 'quoteInputUpdate',
|
|
14
|
+
QUOTE_OUTPUT_UPDATE = 'quoteOutputUpdate',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export enum WalletEventTypes {
|
|
18
|
+
CONNECT = 'connect',
|
|
19
|
+
DISCONNECT = 'disconnect',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type QuoteInputUpdateEventPayload = {
|
|
23
|
+
fromBlockchain?: string;
|
|
24
|
+
toBlockchain?: string;
|
|
25
|
+
fromToken?: { symbol: string; name: string | null; address: string | null };
|
|
26
|
+
toToken?: { symbol: string; name: string | null; address: string | null };
|
|
27
|
+
requestAmount?: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type QuoteUpdateEventPayload = Pick<
|
|
31
|
+
SelectedQuote,
|
|
32
|
+
'requestAmount' | 'swaps' | 'outputAmount' | 'resultType' | 'tags'
|
|
33
|
+
> | null;
|
|
34
|
+
|
|
35
|
+
export type ConnectWalletEventPayload = {
|
|
36
|
+
walletType: string;
|
|
37
|
+
accounts: Account[];
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type DisconnectWalletEventPayload = {
|
|
41
|
+
walletType: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type QuoteEventData =
|
|
45
|
+
| {
|
|
46
|
+
type: QuoteEventTypes.QUOTE_INPUT_UPDATE;
|
|
47
|
+
payload: QuoteInputUpdateEventPayload;
|
|
48
|
+
}
|
|
49
|
+
| {
|
|
50
|
+
type: QuoteEventTypes.QUOTE_OUTPUT_UPDATE;
|
|
51
|
+
payload: QuoteUpdateEventPayload;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type WalletEventData =
|
|
55
|
+
| {
|
|
56
|
+
type: WalletEventTypes.CONNECT;
|
|
57
|
+
payload: ConnectWalletEventPayload;
|
|
58
|
+
}
|
|
59
|
+
| {
|
|
60
|
+
type: WalletEventTypes.DISCONNECT;
|
|
61
|
+
payload: DisconnectWalletEventPayload;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export enum WidgetEvents {
|
|
65
|
+
RouteEvent = QueueManagerEvents.RouteEvent,
|
|
66
|
+
StepEvent = QueueManagerEvents.StepEvent,
|
|
67
|
+
QuoteEvent = 'quoteEvent',
|
|
68
|
+
WalletEvent = 'walletEvent',
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type Events = {
|
|
72
|
+
[WidgetEvents.RouteEvent]: RouteEventData;
|
|
73
|
+
[WidgetEvents.StepEvent]: StepEventData;
|
|
74
|
+
[WidgetEvents.QuoteEvent]: QuoteEventData;
|
|
75
|
+
[WidgetEvents.WalletEvent]: WalletEventData;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
declare type EventHandler<T = unknown> = (event: T) => void;
|
|
79
|
+
|
|
80
|
+
export type WidgetEventEmitter = {
|
|
81
|
+
on<Key extends WidgetEvents>(
|
|
82
|
+
type: Key,
|
|
83
|
+
handler: EventHandler<Events[Key]>
|
|
84
|
+
): void;
|
|
85
|
+
off<Key extends WidgetEvents>(
|
|
86
|
+
type: Key,
|
|
87
|
+
handler?: EventHandler<Events[Key]>
|
|
88
|
+
): void;
|
|
89
|
+
};
|
package/src/types/index.ts
CHANGED
package/src/types/wallets.ts
CHANGED
|
@@ -24,7 +24,8 @@ export type TokensBalance = {
|
|
|
24
24
|
[key: TokenHash]: Balance;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
export type
|
|
27
|
+
export type WalletInfoWithExtra = WalletInfo & {
|
|
28
28
|
namespaces?: Namespace[];
|
|
29
29
|
singleNamespace?: boolean;
|
|
30
|
+
needsDerivationPath?: boolean;
|
|
30
31
|
};
|
package/src/utils/common.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { WalletInfoWithExtra } from '../types';
|
|
1
2
|
import type { Token } from 'rango-sdk';
|
|
2
3
|
|
|
3
|
-
import { BlockchainCategories } from '@rango-dev/ui';
|
|
4
|
+
import { BlockchainCategories, WalletState } from '@rango-dev/ui';
|
|
4
5
|
import { TransactionType } from 'rango-sdk';
|
|
5
6
|
|
|
6
7
|
import { WIDGET_UI_ID } from '../constants';
|
|
@@ -247,3 +248,13 @@ export const getFontUrlByName = (fontName: string) => {
|
|
|
247
248
|
const font = SUPPORTED_FONTS.find((font) => font.value === fontName);
|
|
248
249
|
return font?.url;
|
|
249
250
|
};
|
|
251
|
+
|
|
252
|
+
export function isSingleWalletActive(
|
|
253
|
+
wallets: WalletInfoWithExtra[],
|
|
254
|
+
multiWallets?: boolean
|
|
255
|
+
) {
|
|
256
|
+
const atLeastOneWalletIsConnected = !!wallets.find(
|
|
257
|
+
(w) => w.state === WalletState.CONNECTED
|
|
258
|
+
);
|
|
259
|
+
return multiWallets === false && atLeastOneWalletIsConnected;
|
|
260
|
+
}
|
package/src/utils/meta.ts
CHANGED
|
@@ -16,6 +16,14 @@ export function getBlockchainShortNameFor(
|
|
|
16
16
|
?.shortName;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
export function getBlockchainImage(
|
|
20
|
+
blockchainName: string,
|
|
21
|
+
blockchains: BlockchainMeta[]
|
|
22
|
+
): string | undefined {
|
|
23
|
+
return blockchains.find((blockchain) => blockchain.name === blockchainName)
|
|
24
|
+
?.logo;
|
|
25
|
+
}
|
|
26
|
+
|
|
19
27
|
export function getSwapperDisplayName(
|
|
20
28
|
swapperId: string,
|
|
21
29
|
swappers: SwapperMeta[]
|
package/src/utils/numbers.ts
CHANGED
|
@@ -4,8 +4,6 @@ import type { BestRouteResponse } from 'rango-sdk';
|
|
|
4
4
|
|
|
5
5
|
import { BigNumber } from 'bignumber.js';
|
|
6
6
|
|
|
7
|
-
import { TOOLTIP_DECIMALS } from '../constants/routing';
|
|
8
|
-
|
|
9
7
|
/*
|
|
10
8
|
* if time > 1h -> rounded with 5 minutes precision
|
|
11
9
|
* if time < 1h -> rounded with 15 seconds precision
|
|
@@ -127,13 +125,3 @@ export const containsText = (text: string, searchText: string) =>
|
|
|
127
125
|
|
|
128
126
|
export const isPositiveNumber = (text?: string) =>
|
|
129
127
|
!!text && parseFloat(text) > 0;
|
|
130
|
-
10;
|
|
131
|
-
|
|
132
|
-
export function formatTooltipNumbers(
|
|
133
|
-
number: BigNumber | string | number | null | undefined
|
|
134
|
-
) {
|
|
135
|
-
return numberToString(number, TOOLTIP_DECIMALS, TOOLTIP_DECIMALS).replace(
|
|
136
|
-
/(?:\.0*|(\.\d+?)0*)$/,
|
|
137
|
-
'$1'
|
|
138
|
-
);
|
|
139
|
-
}
|
package/src/utils/providers.ts
CHANGED
|
@@ -8,6 +8,7 @@ export interface ProvidersOptions {
|
|
|
8
8
|
walletConnectListedDesktopWalletLink?: NonNullable<
|
|
9
9
|
WidgetConfig['__UNSTABLE_OR_INTERNAL__']
|
|
10
10
|
>['walletConnectListedDesktopWalletLink'];
|
|
11
|
+
trezorManifest: WidgetConfig['trezorManifest'];
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -27,6 +28,9 @@ export function matchAndGenerateProviders(
|
|
|
27
28
|
options?.walletConnectListedDesktopWalletLink,
|
|
28
29
|
},
|
|
29
30
|
selectedProviders: providers,
|
|
31
|
+
trezor: options?.trezorManifest
|
|
32
|
+
? { manifest: options.trezorManifest }
|
|
33
|
+
: undefined,
|
|
30
34
|
});
|
|
31
35
|
|
|
32
36
|
if (providers) {
|
package/src/utils/wallets.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
SelectedQuote,
|
|
6
6
|
TokensBalance,
|
|
7
7
|
Wallet,
|
|
8
|
-
|
|
8
|
+
WalletInfoWithExtra,
|
|
9
9
|
} from '../types';
|
|
10
10
|
import type { WalletInfo as ModalWalletInfo } from '@rango-dev/ui';
|
|
11
11
|
import type {
|
|
@@ -68,7 +68,7 @@ export function mapWalletTypesToWalletInfo(
|
|
|
68
68
|
getWalletInfo: (type: WalletType) => WalletInfo,
|
|
69
69
|
list: WalletType[],
|
|
70
70
|
chain?: string
|
|
71
|
-
):
|
|
71
|
+
): WalletInfoWithExtra[] {
|
|
72
72
|
return list
|
|
73
73
|
.filter((wallet) => !EXCLUDED_WALLETS.includes(wallet as WalletTypes))
|
|
74
74
|
.filter((wallet) => {
|
|
@@ -96,6 +96,7 @@ export function mapWalletTypesToWalletInfo(
|
|
|
96
96
|
namespaces,
|
|
97
97
|
singleNamespace,
|
|
98
98
|
supportedChains,
|
|
99
|
+
needsDerivationPath,
|
|
99
100
|
} = getWalletInfo(type);
|
|
100
101
|
const blockchainTypes = removeDuplicateFrom(
|
|
101
102
|
supportedChains.map((item) => item.type)
|
|
@@ -112,6 +113,7 @@ export function mapWalletTypesToWalletInfo(
|
|
|
112
113
|
namespaces,
|
|
113
114
|
singleNamespace,
|
|
114
115
|
blockchainTypes,
|
|
116
|
+
needsDerivationPath,
|
|
115
117
|
};
|
|
116
118
|
});
|
|
117
119
|
}
|
|
@@ -434,8 +436,8 @@ export function areTokensEqual(
|
|
|
434
436
|
}
|
|
435
437
|
|
|
436
438
|
export function sortWalletsBasedOnConnectionState(
|
|
437
|
-
wallets:
|
|
438
|
-
):
|
|
439
|
+
wallets: WalletInfoWithExtra[]
|
|
440
|
+
): WalletInfoWithExtra[] {
|
|
439
441
|
return wallets.sort(
|
|
440
442
|
(a, b) =>
|
|
441
443
|
Number(b.state === WalletStatus.CONNECTED) -
|
|
@@ -549,7 +551,7 @@ export function filterBlockchainsByWalletTypes(
|
|
|
549
551
|
}
|
|
550
552
|
|
|
551
553
|
export function filterWalletsByCategory(
|
|
552
|
-
wallets:
|
|
554
|
+
wallets: WalletInfoWithExtra[],
|
|
553
555
|
category: string
|
|
554
556
|
) {
|
|
555
557
|
if (category === BlockchainCategories.ALL) {
|