@@ -16,17 +16,21 @@ import {
16
16
isHexString ,
17
17
node ,
18
18
prettifyAttoAlphAmount ,
19
+ prettifyTokenAmount ,
19
20
} from '@alephium/web3'
20
21
import CopyTextarea from '../Misc/CopyTextarea'
21
- import { useAlephium } from '../../utils/utils'
22
+ import { useAlephium , useTokenList } from '../../utils/utils'
22
23
import MyTable from '../Misc/MyTable'
24
+ import { TokenInfo } from '@alephium/token-list'
23
25
24
26
type P2MPKUnlockScript = { pubkey : string ; index : number } [ ]
27
+ type TxInfo = { recipient : string ; tokens : { symbol : string , amount : string } [ ] ; fee : string ; txId : string }
25
28
26
29
function SignMultisigTx ( ) {
27
30
const [ signature , setSignature ] = useState <
28
31
{ signer : string ; signature : string } | undefined
29
32
> ( )
33
+ const tokens = useTokenList ( )
30
34
const [ unsignedTx , setUnsignedTx ] = useState < string | undefined > ( )
31
35
const [ loadingTxInfo , setLoadingTxInfo ] = useState < boolean > ( false )
32
36
const [ multisigConfig , setMultisigConfig ] = useState <
@@ -35,9 +39,7 @@ function SignMultisigTx() {
35
39
const [ unlockScript , setUnlockScript ] = useState <
36
40
P2MPKUnlockScript | undefined
37
41
> ( )
38
- const [ txInfo , setTxInfo ] = useState <
39
- { recipient : string ; amount : string ; fee : string ; txId : string } | undefined
40
- > ( )
42
+ const [ txInfo , setTxInfo ] = useState < TxInfo > ( )
41
43
const { account, signer, connectionStatus } = useWallet ( )
42
44
43
45
const [ loadingTxError , setLoadingTxError ] = useState < string > ( )
@@ -56,21 +58,10 @@ function SignMultisigTx() {
56
58
const unlockScript = decodeUnlockScript (
57
59
decodedTx . unsignedTx . inputs [ 0 ] . unlockScript
58
60
)
59
- const recipientOutput = decodedTx . unsignedTx . fixedOutputs [ 0 ]
60
61
const multisigConfig = getMultisigByUnlockScript ( unlockScript )
61
62
setUnlockScript ( unlockScript )
62
63
setMultisigConfig ( multisigConfig )
63
- setTxInfo ( {
64
- recipient : recipientOutput . address ,
65
- amount : prettifyAttoAlphAmount (
66
- BigInt ( recipientOutput . attoAlphAmount )
67
- ) ! ,
68
- fee : prettifyAttoAlphAmount (
69
- BigInt ( decodedTx . unsignedTx . gasPrice ) *
70
- BigInt ( decodedTx . unsignedTx . gasAmount )
71
- ) ! ,
72
- txId : decodedTx . unsignedTx . txId ,
73
- } )
64
+ setTxInfo ( getDecodedTxInfo ( decodedTx , tokens ) )
74
65
setLoadingTxInfo ( false )
75
66
setLoadingTxError ( undefined )
76
67
} catch ( error ) {
@@ -184,7 +175,11 @@ function SignMultisigTx() {
184
175
< Mark color = "red" > unknown</ Mark >
185
176
) ,
186
177
Recipient : < CopyTextarea value = { txInfo ?. recipient ?? '' } /> ,
187
- 'ALPH Amount' : txInfo ?. amount + ' ALPH' ,
178
+ 'Token Amount' : txInfo ?. tokens . map ( ( { symbol, amount } ) => (
179
+ < Box key = { symbol } >
180
+ { amount } { symbol }
181
+ </ Box >
182
+ ) ) ,
188
183
'Transaction Fee' : txInfo ?. fee + ' ALPH' ,
189
184
'Transaction Hash' : < CopyTextarea value = { txInfo ?. txId ?? '' } /> ,
190
185
} }
@@ -285,4 +280,34 @@ async function getDecodedUnsignedTx(
285
280
return decodedTx
286
281
}
287
282
283
+ function getDecodedTxInfo (
284
+ decodedTx : node . DecodeUnsignedTxResult ,
285
+ tokens : TokenInfo [ ]
286
+ ) : TxInfo {
287
+ const recipientOutput = decodedTx . unsignedTx . fixedOutputs [ 0 ]
288
+ return {
289
+ recipient : recipientOutput . address ,
290
+ tokens : [
291
+ {
292
+ symbol : 'ALPH' ,
293
+ amount : prettifyAttoAlphAmount ( BigInt ( recipientOutput . attoAlphAmount ) ) ! ,
294
+ } ,
295
+ ...recipientOutput . tokens . map ( ( token ) => {
296
+ const tokenInfo = tokens . find ( ( t ) => t . id === token . id )
297
+ return {
298
+ symbol : tokenInfo ?. symbol ?? token . id ,
299
+ amount :
300
+ prettifyTokenAmount ( token . amount , tokenInfo ?. decimals ?? 0 ) ??
301
+ '???' ,
302
+ }
303
+ } ) ,
304
+ ] ,
305
+ fee : prettifyAttoAlphAmount (
306
+ BigInt ( decodedTx . unsignedTx . gasPrice ) *
307
+ BigInt ( decodedTx . unsignedTx . gasAmount )
308
+ ) ! ,
309
+ txId : decodedTx . unsignedTx . txId ,
310
+ }
311
+ }
312
+
288
313
export default SignMultisigTx
0 commit comments