@unisat/wallet-state 1.0.4 → 1.1.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/LICENSE +0 -5
- package/lib/index.d.mts +2012 -200
- package/lib/index.d.ts +2012 -200
- package/lib/index.js +6951 -570
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +6754 -517
- package/lib/index.mjs.map +1 -1
- package/lib/types/index.d.mts +1 -1
- package/lib/types/index.d.ts +1 -1
- package/package.json +19 -15
- package/src/.DS_Store +0 -0
- package/src/context/ApprovalContext.tsx +27 -0
- package/src/context/DeviceContext.tsx +36 -0
- package/src/context/I18nContext.tsx +14 -172
- package/src/context/NavigationContext.tsx +305 -0
- package/src/context/PriceContext.tsx +2 -2
- package/src/context/StorageContext.tsx +393 -0
- package/src/context/ToolsContext.tsx +50 -0
- package/src/context/WalletContext.tsx +119 -108
- package/src/context/index.ts +17 -2
- package/src/hooks/accounts.ts +11 -5
- package/src/hooks/browser.ts +11 -0
- package/src/hooks/global.ts +170 -7
- package/src/hooks/index.ts +1 -2
- package/src/hooks/settings.ts +28 -37
- package/src/hooks/transactions.ts +28 -155
- package/src/hooks/ui.ts +232 -36
- package/src/index.ts +33 -24
- package/src/reducers/accounts.ts +19 -2
- package/src/reducers/browser.ts +223 -0
- package/src/reducers/global.ts +67 -1
- package/src/reducers/index.ts +1 -0
- package/src/reducers/transactions.ts +0 -9
- package/src/reducers/ui.ts +127 -8
- package/src/types/index.ts +1 -1
- package/src/ui-hooks/index.ts +107 -0
- package/src/ui-hooks/useActionOverviewSectionLogic.ts +150 -0
- package/src/ui-hooks/useAddressTypeScreenLogic.ts +160 -0
- package/src/ui-hooks/useAlkanesBalanceCardLogic.ts +41 -0
- package/src/ui-hooks/useAlkanesCollectionListLogic.ts +68 -0
- package/src/ui-hooks/useAlkanesListLogic.ts +69 -0
- package/src/ui-hooks/useAlkanesNFTListLogic.ts +42 -0
- package/src/ui-hooks/useAlkanesNFTScreenLogic.ts +45 -0
- package/src/ui-hooks/useAlkanesTokenScreenLogic.ts +130 -0
- package/src/ui-hooks/useAmountInputLogic.ts +80 -0
- package/src/ui-hooks/useAnnouncementCardLogic.ts +91 -0
- package/src/ui-hooks/useBRC20BalanceCardLogic.ts +115 -0
- package/src/ui-hooks/useBRC20InscribeTransferLogic.ts +398 -0
- package/src/ui-hooks/useBRC20ListLogic.ts +75 -0
- package/src/ui-hooks/useBRC20ProgListLogic.ts +77 -0
- package/src/ui-hooks/useBRC20SendScreenLogic.ts +411 -0
- package/src/ui-hooks/useBRC20SingleStepScreenLogic.ts +208 -0
- package/src/ui-hooks/useBRC20TokenScreenLogic.ts +469 -0
- package/src/ui-hooks/useBalanceCardLogic.ts +164 -0
- package/src/ui-hooks/useBtcDisplayLogic.ts +16 -0
- package/src/ui-hooks/useCAT20BalanceCardLogic.ts +35 -0
- package/src/ui-hooks/useCAT20ListLogic.ts +83 -0
- package/src/ui-hooks/useCAT20TokenScreenLogic.ts +122 -0
- package/src/ui-hooks/useCAT721ListLogic.ts +68 -0
- package/src/ui-hooks/useCAT721NFTScreenLogic.ts +37 -0
- package/src/ui-hooks/useCreatePasswordScreenLogic.ts +92 -0
- package/src/ui-hooks/useCreateWalletLogicImportWordsStep.ts +299 -0
- package/src/ui-hooks/useEditAccountNameScreenLogic.ts +71 -0
- package/src/ui-hooks/useEditContactScreenLogic.ts +162 -0
- package/src/ui-hooks/useEditWalletNameScreenLogic.ts +58 -0
- package/src/ui-hooks/useExportMnemonicsScreenLogic.ts +75 -0
- package/src/ui-hooks/useExportPrivateKeyScreenLogic.ts +64 -0
- package/src/ui-hooks/useFeeRateBarLogic.ts +303 -0
- package/src/ui-hooks/useInfiniteList.ts +85 -0
- package/src/ui-hooks/useInscriptionListLogic.ts +68 -0
- package/src/ui-hooks/useLockTimePageLogic.ts +43 -0
- package/src/ui-hooks/useNotificationsLogic.ts +115 -0
- package/src/ui-hooks/useOrdinalsInscriptionScreenLogic.ts +130 -0
- package/src/ui-hooks/useRunesBalanceCardLogic.ts +44 -0
- package/src/ui-hooks/useRunesListLogic.ts +74 -0
- package/src/ui-hooks/useRunesTokenScreenLogic.ts +149 -0
- package/src/ui-hooks/useSecurityCardLogic.ts +0 -0
- package/src/ui-hooks/useSendAlkanesNFTScreenLogic.ts +138 -0
- package/src/ui-hooks/useSendAlkanesScreenLogic.ts +192 -0
- package/src/ui-hooks/useSendCAT20ScreenLogic.ts +297 -0
- package/src/ui-hooks/useSendCAT721ScreenLogic.ts +205 -0
- package/src/ui-hooks/useSendOrdinalsInscriptionScreenLogic.ts +137 -0
- package/src/ui-hooks/useSendRunesScreenLogic.ts +172 -0
- package/src/ui-hooks/useSettingsTabScreenLogic.ts +211 -0
- package/src/ui-hooks/useSignMessageLogic.ts +302 -0
- package/src/ui-hooks/useSignPsbtLogic.ts +517 -0
- package/src/ui-hooks/useSplitOrdinalsInscriptionScreenLogic.ts +95 -0
- package/src/ui-hooks/useTxConfirmScreenLogic.ts +47 -0
- package/src/ui-hooks/useTxCreateScreenLogic.ts +161 -0
- package/src/ui-hooks/useTxFailScreenLogic.ts +26 -0
- package/src/ui-hooks/useTxSuccessScreenLogic.ts +33 -0
- package/src/updater/accounts.ts +11 -11
- package/src/utils/bitcoin-utils.ts +17 -8
- package/src/utils/eventBus.ts +2 -1
- package/src/utils/password-utils.ts +78 -0
- package/src/utils/ui-utils.ts +28 -0
- package/src/hooks/approval.ts +0 -72
- package/src/hooks/i18n.ts +0 -53
- package/src/utils/i18n.ts +0 -41
|
@@ -1,23 +1,14 @@
|
|
|
1
1
|
import { useCallback, useMemo } from 'react'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { ToAddressInfo, ToSignData, UnspentOutput } from '@unisat/wallet-shared'
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import { AppState } from '..'
|
|
5
|
+
import { numUtils, timeUtils } from '@unisat/base-utils'
|
|
6
|
+
import { AppState, useI18n, useTools } from '..'
|
|
7
|
+
import { useWallet } from '../context/WalletContext'
|
|
9
8
|
import { useAccountAddress, useCurrentAccount } from '../hooks/accounts'
|
|
10
9
|
import { accountActions } from '../reducers/accounts'
|
|
11
|
-
import { useAppDispatch, useAppSelector } from './base'
|
|
12
10
|
import { transactionsActions } from '../reducers/transactions'
|
|
13
|
-
import {
|
|
14
|
-
import { useWallet } from '../context/WalletContext'
|
|
15
|
-
|
|
16
|
-
function useTools() {
|
|
17
|
-
return {
|
|
18
|
-
showLoading: (show: boolean) => {},
|
|
19
|
-
}
|
|
20
|
-
}
|
|
11
|
+
import { useAppDispatch, useAppSelector } from './base'
|
|
21
12
|
|
|
22
13
|
export function useTransactionsState(): AppState['transactions'] {
|
|
23
14
|
return useAppSelector(state => state.transactions)
|
|
@@ -34,15 +25,13 @@ export function usePrepareSendBTCCallback() {
|
|
|
34
25
|
const fromAddress = useAccountAddress()
|
|
35
26
|
const utxos = useUtxos()
|
|
36
27
|
const fetchUtxos = useFetchUtxosCallback()
|
|
37
|
-
|
|
38
|
-
const btcUnit = useBTCUnit()
|
|
28
|
+
|
|
39
29
|
const { t } = useI18n()
|
|
40
30
|
return useCallback(
|
|
41
31
|
async ({
|
|
42
32
|
toAddressInfo,
|
|
43
33
|
toAmount,
|
|
44
34
|
feeRate,
|
|
45
|
-
enableRBF,
|
|
46
35
|
memo,
|
|
47
36
|
memos,
|
|
48
37
|
disableAutoAdjust,
|
|
@@ -50,7 +39,6 @@ export function usePrepareSendBTCCallback() {
|
|
|
50
39
|
toAddressInfo: ToAddressInfo
|
|
51
40
|
toAmount: number
|
|
52
41
|
feeRate?: number
|
|
53
|
-
enableRBF: boolean
|
|
54
42
|
memo?: string
|
|
55
43
|
memos?: string[]
|
|
56
44
|
disableAutoAdjust?: boolean
|
|
@@ -70,47 +58,26 @@ export function usePrepareSendBTCCallback() {
|
|
|
70
58
|
const summary = await wallet.getFeeSummary()
|
|
71
59
|
feeRate = summary.list[1]!.feeRate
|
|
72
60
|
}
|
|
73
|
-
let res:
|
|
74
|
-
psbtHex: string
|
|
75
|
-
rawtx: string
|
|
76
|
-
fee: number
|
|
77
|
-
}
|
|
61
|
+
let res: ToSignData
|
|
78
62
|
|
|
79
63
|
if (safeBalance === toAmount && !disableAutoAdjust) {
|
|
80
|
-
res = await wallet.
|
|
64
|
+
res = await wallet.createSendAllBTCPsbt({
|
|
81
65
|
to: toAddressInfo.address,
|
|
82
66
|
btcUtxos: _utxos,
|
|
83
|
-
enableRBF,
|
|
84
67
|
feeRate,
|
|
85
68
|
})
|
|
86
69
|
} else {
|
|
87
|
-
res = await wallet.
|
|
70
|
+
res = await wallet.createSendBTCPsbt({
|
|
88
71
|
to: toAddressInfo.address,
|
|
89
72
|
amount: toAmount,
|
|
90
73
|
btcUtxos: _utxos,
|
|
91
|
-
enableRBF,
|
|
92
74
|
feeRate,
|
|
93
75
|
memo: memo!,
|
|
94
76
|
memos: memos!,
|
|
95
77
|
})
|
|
96
78
|
}
|
|
97
79
|
|
|
98
|
-
|
|
99
|
-
(transactionsActions as any).updateBitcoinTx({
|
|
100
|
-
rawtx: res.rawtx,
|
|
101
|
-
psbtHex: res.psbtHex,
|
|
102
|
-
fromAddress,
|
|
103
|
-
feeRate,
|
|
104
|
-
enableRBF,
|
|
105
|
-
})
|
|
106
|
-
)
|
|
107
|
-
const rawTxInfo: RawTxInfo = {
|
|
108
|
-
psbtHex: res.psbtHex,
|
|
109
|
-
rawtx: res.rawtx,
|
|
110
|
-
toAddressInfo,
|
|
111
|
-
fee: res.fee,
|
|
112
|
-
}
|
|
113
|
-
return rawTxInfo
|
|
80
|
+
return res
|
|
114
81
|
},
|
|
115
82
|
[dispatch, wallet, fromAddress, utxos, fetchUtxos]
|
|
116
83
|
)
|
|
@@ -119,9 +86,6 @@ export function usePrepareSendBTCCallback() {
|
|
|
119
86
|
export function usePrepareSendBypassHeadOffsetsCallback() {
|
|
120
87
|
const dispatch = useAppDispatch()
|
|
121
88
|
const wallet = useWallet()
|
|
122
|
-
const fromAddress = useAccountAddress()
|
|
123
|
-
const account = useCurrentAccount()
|
|
124
|
-
const btcUnit = useBTCUnit()
|
|
125
89
|
return useCallback(
|
|
126
90
|
async ({
|
|
127
91
|
toAddressInfo,
|
|
@@ -132,7 +96,7 @@ export function usePrepareSendBypassHeadOffsetsCallback() {
|
|
|
132
96
|
toAmount: number
|
|
133
97
|
feeRate: number
|
|
134
98
|
}) => {
|
|
135
|
-
const res = await wallet.
|
|
99
|
+
const res = await wallet.createSendBTCOffsetPsbt(
|
|
136
100
|
[
|
|
137
101
|
{
|
|
138
102
|
address: toAddressInfo.address,
|
|
@@ -141,24 +105,9 @@ export function usePrepareSendBypassHeadOffsetsCallback() {
|
|
|
141
105
|
],
|
|
142
106
|
feeRate
|
|
143
107
|
)
|
|
144
|
-
|
|
145
|
-
dispatch(
|
|
146
|
-
(transactionsActions as any).updateBitcoinTx({
|
|
147
|
-
rawtx: res.rawtx,
|
|
148
|
-
psbtHex: res.psbtHex,
|
|
149
|
-
fromAddress,
|
|
150
|
-
feeRate,
|
|
151
|
-
})
|
|
152
|
-
)
|
|
153
|
-
const rawTxInfo: RawTxInfo = {
|
|
154
|
-
psbtHex: res.psbtHex,
|
|
155
|
-
rawtx: res.rawtx,
|
|
156
|
-
toAddressInfo,
|
|
157
|
-
fee: res.fee,
|
|
158
|
-
}
|
|
159
|
-
return rawTxInfo
|
|
108
|
+
return res
|
|
160
109
|
},
|
|
161
|
-
[dispatch, wallet
|
|
110
|
+
[dispatch, wallet]
|
|
162
111
|
)
|
|
163
112
|
}
|
|
164
113
|
|
|
@@ -196,7 +145,7 @@ export function usePushBitcoinTxCallback() {
|
|
|
196
145
|
|
|
197
146
|
return ret
|
|
198
147
|
},
|
|
199
|
-
[dispatch, wallet]
|
|
148
|
+
[dispatch, wallet, tools]
|
|
200
149
|
)
|
|
201
150
|
}
|
|
202
151
|
|
|
@@ -211,20 +160,17 @@ export function usePrepareSendOrdinalsInscriptionCallback() {
|
|
|
211
160
|
const fromAddress = useAccountAddress()
|
|
212
161
|
const utxos = useUtxos()
|
|
213
162
|
const fetchUtxos = useFetchUtxosCallback()
|
|
214
|
-
const account = useCurrentAccount()
|
|
215
163
|
return useCallback(
|
|
216
164
|
async ({
|
|
217
165
|
toAddressInfo,
|
|
218
166
|
inscriptionId,
|
|
219
167
|
feeRate,
|
|
220
168
|
outputValue,
|
|
221
|
-
enableRBF,
|
|
222
169
|
}: {
|
|
223
170
|
toAddressInfo: ToAddressInfo
|
|
224
171
|
inscriptionId: string
|
|
225
172
|
feeRate?: number
|
|
226
173
|
outputValue?: number
|
|
227
|
-
enableRBF: boolean
|
|
228
174
|
}) => {
|
|
229
175
|
if (!feeRate) {
|
|
230
176
|
const summary = await wallet.getFeeSummary()
|
|
@@ -236,31 +182,15 @@ export function usePrepareSendOrdinalsInscriptionCallback() {
|
|
|
236
182
|
btcUtxos = await fetchUtxos()
|
|
237
183
|
}
|
|
238
184
|
|
|
239
|
-
const
|
|
185
|
+
const toSignData = await wallet.createSendInscriptionPsbt({
|
|
240
186
|
to: toAddressInfo.address,
|
|
241
187
|
inscriptionId,
|
|
242
188
|
feeRate,
|
|
243
189
|
outputValue: outputValue!,
|
|
244
|
-
enableRBF,
|
|
245
190
|
btcUtxos,
|
|
246
191
|
})
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
rawtx: res.rawtx,
|
|
250
|
-
psbtHex: res.psbtHex,
|
|
251
|
-
fromAddress,
|
|
252
|
-
// inscription,
|
|
253
|
-
feeRate,
|
|
254
|
-
outputValue,
|
|
255
|
-
enableRBF,
|
|
256
|
-
})
|
|
257
|
-
)
|
|
258
|
-
const rawTxInfo: RawTxInfo = {
|
|
259
|
-
psbtHex: res.psbtHex,
|
|
260
|
-
rawtx: res.rawtx,
|
|
261
|
-
toAddressInfo,
|
|
262
|
-
}
|
|
263
|
-
return rawTxInfo
|
|
192
|
+
|
|
193
|
+
return toSignData
|
|
264
194
|
},
|
|
265
195
|
[dispatch, wallet, fromAddress, utxos]
|
|
266
196
|
)
|
|
@@ -272,18 +202,15 @@ export function usePrepareSendOrdinalsInscriptionsCallback() {
|
|
|
272
202
|
const fromAddress = useAccountAddress()
|
|
273
203
|
const fetchUtxos = useFetchUtxosCallback()
|
|
274
204
|
const utxos = useUtxos()
|
|
275
|
-
const account = useCurrentAccount()
|
|
276
205
|
return useCallback(
|
|
277
206
|
async ({
|
|
278
207
|
toAddressInfo,
|
|
279
208
|
inscriptionIds,
|
|
280
209
|
feeRate,
|
|
281
|
-
enableRBF,
|
|
282
210
|
}: {
|
|
283
211
|
toAddressInfo: ToAddressInfo
|
|
284
212
|
inscriptionIds: string[]
|
|
285
213
|
feeRate?: number
|
|
286
|
-
enableRBF: boolean
|
|
287
214
|
}) => {
|
|
288
215
|
if (!feeRate) {
|
|
289
216
|
const summary = await wallet.getFeeSummary()
|
|
@@ -294,28 +221,14 @@ export function usePrepareSendOrdinalsInscriptionsCallback() {
|
|
|
294
221
|
if (btcUtxos.length === 0) {
|
|
295
222
|
btcUtxos = await fetchUtxos()
|
|
296
223
|
}
|
|
297
|
-
const res = await wallet.
|
|
224
|
+
const res = await wallet.createSendMultipleInscriptionsPsbt({
|
|
298
225
|
to: toAddressInfo.address,
|
|
299
226
|
inscriptionIds,
|
|
300
227
|
feeRate,
|
|
301
|
-
enableRBF,
|
|
302
228
|
btcUtxos,
|
|
303
229
|
})
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
rawtx: res.rawtx,
|
|
307
|
-
psbtHex: res.psbtHex,
|
|
308
|
-
fromAddress,
|
|
309
|
-
feeRate,
|
|
310
|
-
enableRBF,
|
|
311
|
-
})
|
|
312
|
-
)
|
|
313
|
-
const rawTxInfo: RawTxInfo = {
|
|
314
|
-
psbtHex: res.psbtHex,
|
|
315
|
-
rawtx: res.rawtx,
|
|
316
|
-
toAddressInfo,
|
|
317
|
-
}
|
|
318
|
-
return rawTxInfo
|
|
230
|
+
|
|
231
|
+
return res
|
|
319
232
|
},
|
|
320
233
|
[dispatch, wallet, fromAddress, utxos]
|
|
321
234
|
)
|
|
@@ -333,44 +246,24 @@ export function useCreateSplitTxCallback() {
|
|
|
333
246
|
inscriptionId,
|
|
334
247
|
feeRate,
|
|
335
248
|
outputValue,
|
|
336
|
-
enableRBF,
|
|
337
249
|
}: {
|
|
338
250
|
inscriptionId: string
|
|
339
251
|
feeRate: number
|
|
340
252
|
outputValue: number
|
|
341
|
-
enableRBF: boolean
|
|
342
253
|
}) => {
|
|
343
254
|
let btcUtxos = utxos
|
|
344
255
|
if (btcUtxos.length === 0) {
|
|
345
256
|
btcUtxos = await fetchUtxos()
|
|
346
257
|
}
|
|
347
258
|
|
|
348
|
-
const res = await wallet.
|
|
259
|
+
const res = await wallet.createSplitInscriptionPsbt({
|
|
349
260
|
inscriptionId,
|
|
350
261
|
feeRate,
|
|
351
262
|
outputValue,
|
|
352
|
-
enableRBF,
|
|
353
263
|
btcUtxos,
|
|
354
264
|
})
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
rawtx: res.rawtx,
|
|
358
|
-
psbtHex: res.psbtHex,
|
|
359
|
-
fromAddress,
|
|
360
|
-
// inscription,
|
|
361
|
-
enableRBF,
|
|
362
|
-
feeRate,
|
|
363
|
-
outputValue,
|
|
364
|
-
})
|
|
365
|
-
)
|
|
366
|
-
const rawTxInfo: RawTxInfo = {
|
|
367
|
-
psbtHex: res.psbtHex,
|
|
368
|
-
rawtx: res.rawtx,
|
|
369
|
-
toAddressInfo: {
|
|
370
|
-
address: fromAddress,
|
|
371
|
-
},
|
|
372
|
-
}
|
|
373
|
-
return { rawTxInfo, splitedCount: res.splitedCount }
|
|
265
|
+
|
|
266
|
+
return res
|
|
374
267
|
},
|
|
375
268
|
[dispatch, wallet, fromAddress, utxos]
|
|
376
269
|
)
|
|
@@ -492,14 +385,12 @@ export function usePrepareSendRunesCallback() {
|
|
|
492
385
|
runeAmount,
|
|
493
386
|
outputValue,
|
|
494
387
|
feeRate,
|
|
495
|
-
enableRBF,
|
|
496
388
|
}: {
|
|
497
389
|
toAddressInfo: ToAddressInfo
|
|
498
390
|
runeid: string
|
|
499
391
|
runeAmount: string
|
|
500
392
|
outputValue?: number
|
|
501
393
|
feeRate: number
|
|
502
|
-
enableRBF: boolean
|
|
503
394
|
}) => {
|
|
504
395
|
if (!feeRate) {
|
|
505
396
|
const summary = await wallet.getFeeSummary()
|
|
@@ -516,35 +407,17 @@ export function usePrepareSendRunesCallback() {
|
|
|
516
407
|
assetUtxos = await fetchAssetUtxosRunes(runeid)
|
|
517
408
|
}
|
|
518
409
|
|
|
519
|
-
const
|
|
410
|
+
const toSignData = await wallet.createSendRunesPsbt({
|
|
520
411
|
to: toAddressInfo.address,
|
|
521
412
|
runeid,
|
|
522
413
|
runeAmount,
|
|
523
414
|
outputValue: outputValue!,
|
|
524
415
|
feeRate,
|
|
525
|
-
enableRBF,
|
|
526
416
|
btcUtxos,
|
|
527
417
|
assetUtxos,
|
|
528
418
|
})
|
|
529
419
|
|
|
530
|
-
|
|
531
|
-
(transactionsActions as any).updateRunesTx({
|
|
532
|
-
rawtx: res.rawtx,
|
|
533
|
-
psbtHex: res.psbtHex,
|
|
534
|
-
fromAddress,
|
|
535
|
-
feeRate,
|
|
536
|
-
enableRBF,
|
|
537
|
-
runeid,
|
|
538
|
-
runeAmount,
|
|
539
|
-
outputValue,
|
|
540
|
-
})
|
|
541
|
-
)
|
|
542
|
-
const rawTxInfo: RawTxInfo = {
|
|
543
|
-
psbtHex: res.psbtHex,
|
|
544
|
-
rawtx: res.rawtx,
|
|
545
|
-
toAddressInfo,
|
|
546
|
-
}
|
|
547
|
-
return rawTxInfo
|
|
420
|
+
return toSignData
|
|
548
421
|
},
|
|
549
422
|
[dispatch, wallet, fromAddress, utxos, assetUtxosRunes, fetchAssetUtxosRunes, account]
|
|
550
423
|
)
|
|
@@ -564,14 +437,14 @@ export function usePrepareSendAlkanesCallback() {
|
|
|
564
437
|
alkaneid: string,
|
|
565
438
|
amount: string,
|
|
566
439
|
feeRate: number,
|
|
567
|
-
|
|
440
|
+
type: 'ft' | 'nft'
|
|
568
441
|
) => {
|
|
569
|
-
return await wallet.
|
|
442
|
+
return await wallet.createSendAlkanesPsbt({
|
|
570
443
|
to: toAddressInfo.address,
|
|
571
444
|
alkaneid,
|
|
572
445
|
amount,
|
|
573
446
|
feeRate,
|
|
574
|
-
|
|
447
|
+
type,
|
|
575
448
|
})
|
|
576
449
|
},
|
|
577
450
|
[wallet, account]
|
package/src/hooks/ui.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import { useMemo } from 'react'
|
|
1
|
+
import { useCallback, useMemo } from 'react'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { CHAINS_MAP, Inscription } from '@unisat/wallet-shared'
|
|
4
|
+
import { AddressType, ChainType } from '@unisat/wallet-types'
|
|
5
5
|
import { getAddressType } from '../utils/bitcoin-utils'
|
|
6
|
-
import { AddressType } from '@unisat/wallet-types'
|
|
7
6
|
|
|
8
7
|
import { AppState, AssetTabKey } from '..'
|
|
9
|
-
import {
|
|
8
|
+
import { useCurrentAddress } from '../hooks/accounts'
|
|
10
9
|
import { useAppDispatch, useAppSelector } from '../hooks/base'
|
|
11
|
-
import { useChainType,
|
|
10
|
+
import { useChainType, useIconBaseUrl, useUnisatWebsite } from '../hooks/settings'
|
|
12
11
|
import { uiActions } from '../reducers/ui'
|
|
13
|
-
import { TypeChain } from '@unisat/wallet-shared'
|
|
14
|
-
import { useLocation } from 'react-router-dom'
|
|
15
12
|
export function useUIState(): AppState['ui'] {
|
|
16
13
|
return useAppSelector(state => state.ui)
|
|
17
14
|
}
|
|
@@ -46,15 +43,110 @@ export function useUpdateUiTxCreateScreen() {
|
|
|
46
43
|
return ({
|
|
47
44
|
toInfo,
|
|
48
45
|
inputAmount,
|
|
49
|
-
enableRBF,
|
|
50
|
-
feeRate,
|
|
51
46
|
}: {
|
|
52
47
|
toInfo?: { address: string; domain: string; inscription?: Inscription }
|
|
53
48
|
inputAmount?: string
|
|
54
|
-
|
|
49
|
+
}) => {
|
|
50
|
+
dispatch(
|
|
51
|
+
(uiActions as any).updateTxCreateScreen({
|
|
52
|
+
toInfo,
|
|
53
|
+
inputAmount,
|
|
54
|
+
})
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function useFeeRateBar() {
|
|
60
|
+
const uiState = useUIState()
|
|
61
|
+
return uiState.feeRateBar
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function useUpdateFeeRateBar() {
|
|
65
|
+
const dispatch = useAppDispatch()
|
|
66
|
+
return ({
|
|
67
|
+
feeRate,
|
|
68
|
+
feeRateInputVal,
|
|
69
|
+
enableLowFeeRate,
|
|
70
|
+
feeOptionIndex,
|
|
71
|
+
showCustomInput,
|
|
72
|
+
}: {
|
|
55
73
|
feeRate?: number
|
|
74
|
+
feeRateInputVal?: string
|
|
75
|
+
enableLowFeeRate?: boolean
|
|
76
|
+
feeOptionIndex?: number
|
|
77
|
+
showCustomInput?: boolean
|
|
56
78
|
}) => {
|
|
57
|
-
dispatch(
|
|
79
|
+
dispatch(
|
|
80
|
+
(uiActions as any).updateFeeRateBar({
|
|
81
|
+
feeRate,
|
|
82
|
+
feeRateInputVal,
|
|
83
|
+
enableLowFeeRate,
|
|
84
|
+
feeOptionIndex,
|
|
85
|
+
showCustomInput,
|
|
86
|
+
})
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function useResetFeeRateBar() {
|
|
92
|
+
const dispatch = useAppDispatch()
|
|
93
|
+
return () => {
|
|
94
|
+
dispatch((uiActions as any).resetFeeRateBar())
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function useAddressInput() {
|
|
99
|
+
const uiState = useUIState()
|
|
100
|
+
return uiState.addressInput
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function useUpdateAddressInput() {
|
|
104
|
+
const dispatch = useAppDispatch()
|
|
105
|
+
return ({ address, domain }: { address?: string; domain?: string }) => {
|
|
106
|
+
dispatch(
|
|
107
|
+
(uiActions as any).updateAddressInput({
|
|
108
|
+
address,
|
|
109
|
+
domain,
|
|
110
|
+
})
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function useResetAddressInput() {
|
|
116
|
+
const dispatch = useAppDispatch()
|
|
117
|
+
return () => {
|
|
118
|
+
dispatch((uiActions as any).resetAddressInput())
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function useAmountInput() {
|
|
123
|
+
const uiState = useUIState()
|
|
124
|
+
return uiState.amountInput
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function useUpdateAmountInput() {
|
|
128
|
+
const dispatch = useAppDispatch()
|
|
129
|
+
return ({ amount }: { amount?: string }) => {
|
|
130
|
+
dispatch(
|
|
131
|
+
(uiActions as any).updateAmountInput({
|
|
132
|
+
amount,
|
|
133
|
+
})
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function useResetAmountInput() {
|
|
139
|
+
const dispatch = useAppDispatch()
|
|
140
|
+
return () => {
|
|
141
|
+
dispatch((uiActions as any).resetAmountInput())
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function useResetTxState() {
|
|
146
|
+
const dispatch = useAppDispatch()
|
|
147
|
+
return () => {
|
|
148
|
+
dispatch((uiActions as any).resetTxCreateScreen())
|
|
149
|
+
dispatch((uiActions as any).resetFeeRateBar())
|
|
58
150
|
}
|
|
59
151
|
}
|
|
60
152
|
|
|
@@ -65,18 +157,32 @@ export function useResetUiTxCreateScreen() {
|
|
|
65
157
|
}
|
|
66
158
|
}
|
|
67
159
|
|
|
68
|
-
export
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
160
|
+
export const useThrottle = (callback, delay, lastCallRef) => {
|
|
161
|
+
return useCallback(
|
|
162
|
+
(...args) => {
|
|
163
|
+
const now = Date.now()
|
|
164
|
+
if (now - lastCallRef.current > delay) {
|
|
165
|
+
lastCallRef.current = now
|
|
166
|
+
callback(...args)
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
[callback, delay, lastCallRef]
|
|
170
|
+
)
|
|
171
|
+
}
|
|
73
172
|
|
|
173
|
+
export function getSupportedAssets(chainType: ChainType, address: string) {
|
|
74
174
|
const assetTabKeys: AssetTabKey[] = []
|
|
175
|
+
|
|
176
|
+
const chain = CHAINS_MAP[chainType]
|
|
177
|
+
const networkType = chain.networkType
|
|
178
|
+
const addressType = getAddressType(address, networkType)
|
|
179
|
+
|
|
75
180
|
const assets = {
|
|
76
181
|
ordinals: false,
|
|
77
182
|
runes: false,
|
|
78
183
|
CAT20: false,
|
|
79
184
|
alkanes: false,
|
|
185
|
+
brc20Prog: false,
|
|
80
186
|
}
|
|
81
187
|
|
|
82
188
|
assets.ordinals = true
|
|
@@ -86,27 +192,35 @@ export function useSupportedAssets() {
|
|
|
86
192
|
assetTabKeys.push(AssetTabKey.RUNES)
|
|
87
193
|
|
|
88
194
|
if (
|
|
89
|
-
chainType === ChainType.FRACTAL_BITCOIN_MAINNET ||
|
|
90
|
-
|
|
195
|
+
(chainType === ChainType.FRACTAL_BITCOIN_MAINNET ||
|
|
196
|
+
chainType === ChainType.FRACTAL_BITCOIN_TESTNET) &&
|
|
197
|
+
(addressType == AddressType.P2TR || addressType == AddressType.P2WPKH)
|
|
91
198
|
) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
assets.CAT20 = true
|
|
95
|
-
assetTabKeys.push(AssetTabKey.CAT)
|
|
96
|
-
}
|
|
199
|
+
assets.CAT20 = true
|
|
200
|
+
assetTabKeys.push(AssetTabKey.CAT)
|
|
97
201
|
}
|
|
98
202
|
|
|
99
|
-
if (chainType === ChainType.
|
|
203
|
+
if (chainType === ChainType.BITCOIN_MAINNET || chainType === ChainType.BITCOIN_SIGNET) {
|
|
100
204
|
assets.alkanes = true
|
|
101
205
|
assetTabKeys.push(AssetTabKey.ALKANES)
|
|
102
206
|
}
|
|
103
207
|
|
|
208
|
+
if (chainType === ChainType.BITCOIN_MAINNET || chainType === ChainType.BITCOIN_SIGNET) {
|
|
209
|
+
assets.brc20Prog = true
|
|
210
|
+
}
|
|
211
|
+
|
|
104
212
|
return {
|
|
105
|
-
tabKeys: assetTabKeys,
|
|
106
213
|
assets,
|
|
107
|
-
|
|
214
|
+
tabKeys: assetTabKeys,
|
|
215
|
+
key: chainType + address + assetTabKeys.join(','),
|
|
108
216
|
}
|
|
109
217
|
}
|
|
218
|
+
export function useSupportedAssets() {
|
|
219
|
+
const chainType = useChainType()
|
|
220
|
+
const currentAddress = useCurrentAddress()
|
|
221
|
+
const supportedAssets = getSupportedAssets(chainType, currentAddress)
|
|
222
|
+
return supportedAssets
|
|
223
|
+
}
|
|
110
224
|
|
|
111
225
|
export const useIsInExpandView = () => {
|
|
112
226
|
// @ts-ignore
|
|
@@ -124,18 +238,100 @@ export const useIsInExpandView = () => {
|
|
|
124
238
|
}, [window.innerWidth])
|
|
125
239
|
}
|
|
126
240
|
|
|
127
|
-
export
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
241
|
+
export function useWalletTopTabScreenState() {
|
|
242
|
+
const uiState = useUIState()
|
|
243
|
+
return uiState.walletTopTabScreen
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export function useBRC20IconInfo(ticker: string) {
|
|
247
|
+
const baseUrl = useIconBaseUrl()
|
|
248
|
+
const iconUrl = `${baseUrl}/brc20/${ticker}`
|
|
249
|
+
const iconShortName = ticker.substring(0, 2)
|
|
250
|
+
const chainType = useChainType()
|
|
251
|
+
if (chainType === ChainType.BITCOIN_MAINNET || chainType === ChainType.FRACTAL_BITCOIN_MAINNET) {
|
|
252
|
+
return { iconUrl, iconShortName }
|
|
131
253
|
}
|
|
132
254
|
|
|
133
|
-
return {
|
|
134
|
-
|
|
255
|
+
return { iconUrl: '', iconShortName }
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export function useRunesIconInfo(spacedRune: string) {
|
|
259
|
+
const baseUrl = useIconBaseUrl()
|
|
260
|
+
const iconUrl = `${baseUrl}/runes/${spacedRune}`
|
|
261
|
+
const iconShortName = spacedRune.substring(0, 2)
|
|
262
|
+
const chainType = useChainType()
|
|
263
|
+
if (chainType === ChainType.BITCOIN_MAINNET || chainType === ChainType.FRACTAL_BITCOIN_MAINNET) {
|
|
264
|
+
return { iconUrl, iconShortName }
|
|
135
265
|
}
|
|
266
|
+
|
|
267
|
+
return { iconUrl: '', iconShortName }
|
|
136
268
|
}
|
|
137
269
|
|
|
138
|
-
export function
|
|
139
|
-
const
|
|
140
|
-
|
|
270
|
+
export function useAlkanesIconInfo(name: string, alkaneid: string) {
|
|
271
|
+
const baseUrl = useIconBaseUrl()
|
|
272
|
+
const iconUrl = `${baseUrl}/alkanes/${name}/${alkaneid}`
|
|
273
|
+
const iconShortName = name.substring(0, 2)
|
|
274
|
+
const chainType = useChainType()
|
|
275
|
+
if (chainType === ChainType.BITCOIN_MAINNET || chainType === ChainType.FRACTAL_BITCOIN_MAINNET) {
|
|
276
|
+
return { iconUrl, iconShortName }
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return { iconUrl: '', iconShortName }
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export function useCAT20IconInfo(name: string, tokenId: string) {
|
|
283
|
+
const baseUrl = useIconBaseUrl()
|
|
284
|
+
const iconUrl = `${baseUrl}/cat20/${name}/${tokenId}`
|
|
285
|
+
const iconShortName = name.substring(0, 2)
|
|
286
|
+
const chainType = useChainType()
|
|
287
|
+
if (chainType === ChainType.BITCOIN_MAINNET || chainType === ChainType.FRACTAL_BITCOIN_MAINNET) {
|
|
288
|
+
return { iconUrl, iconShortName }
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return { iconUrl: '', iconShortName }
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export function useBRC20MarketPlaceWebsite(ticker: string) {
|
|
295
|
+
const chainType = useChainType()
|
|
296
|
+
const unisatWebsite = useUnisatWebsite()
|
|
297
|
+
if (chainType === ChainType.BITCOIN_MAINNET) {
|
|
298
|
+
if (ticker.length == 6) {
|
|
299
|
+
return `${unisatWebsite}/market/brc20_prog?tick=${ticker}`
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return `${unisatWebsite}/market/brc20?tick=${ticker}`
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export function useRunesMarketUrl(ticker: string) {
|
|
306
|
+
const unisatWebsite = useUnisatWebsite()
|
|
307
|
+
return `${unisatWebsite}/runes/market?tick=${ticker}`
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export function useAlkanesMarketPlaceWebsite(alkaneid: string) {
|
|
311
|
+
const unisatWebsite = useUnisatWebsite()
|
|
312
|
+
return `${unisatWebsite}/alkanes/market?tick=${alkaneid}`
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export function useCAT20MarketPlaceWebsite(tokenId: string) {
|
|
316
|
+
const unisatWebsite = useUnisatWebsite()
|
|
317
|
+
return `${unisatWebsite}/dex/cat20/${tokenId}`
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export function useRunesInscribeUrl(rune: string) {
|
|
321
|
+
const unisatWebsite = useUnisatWebsite()
|
|
322
|
+
const newUrl = `${unisatWebsite}/runes/inscribe?only=1&tab=mint&rune=${rune}`
|
|
323
|
+
return newUrl
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export function useBalanceCardDetailExpanded() {
|
|
327
|
+
const uiState = useUIState()
|
|
328
|
+
return uiState.balanceDetailExpanded
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export function useToggleBalanceCardDetailExpanded() {
|
|
332
|
+
const { balanceDetailExpanded } = useUIState()
|
|
333
|
+
const dispatch = useAppDispatch()
|
|
334
|
+
return useCallback(() => {
|
|
335
|
+
dispatch((uiActions as any).setBalanceDetailExpanded(!balanceDetailExpanded))
|
|
336
|
+
}, [dispatch, balanceDetailExpanded])
|
|
141
337
|
}
|