@@ -5,18 +5,18 @@ import { Account, Address, Operation } from "@ledgerhq/types-live";
5
5
import {
6
6
makeUnsignedSTXTokenTransfer ,
7
7
UnsignedTokenTransferOptions ,
8
- createMessageSignature
8
+ createMessageSignature ,
9
9
} from "@stacks/transactions" ;
10
10
11
11
import {
12
12
GetAccountShape ,
13
- GetAccountShapeArg0
13
+ AccountShapeInfo ,
14
14
} from "../../../../bridge/jsHelpers" ;
15
15
import { decodeAccountId , encodeAccountId } from "../../../../account" ;
16
16
import {
17
17
fetchBalances ,
18
18
fetchBlockHeight ,
19
- fetchFullTxs
19
+ fetchFullTxs ,
20
20
} from "../../bridge/utils/api" ;
21
21
import { StacksNetwork , TransactionResponse } from "./types" ;
22
22
import { getCryptoCurrencyById } from "../../../../currencies" ;
@@ -30,7 +30,7 @@ export const getTxToBroadcast = async (
30
30
value,
31
31
recipients,
32
32
fee,
33
- extra : { xpub, nonce, anchorMode, network, memo }
33
+ extra : { xpub, nonce, anchorMode, network, memo } ,
34
34
} = operation ;
35
35
36
36
const options : UnsignedTokenTransferOptions = {
@@ -60,66 +60,69 @@ export const getAddress = (a: Account): Address =>
60
60
? a . freshAddresses [ 0 ]
61
61
: { address : a . freshAddress , derivationPath : a . freshAddressPath } ;
62
62
63
- export const mapTxToOps = ( accountID , { address } : GetAccountShapeArg0 ) => (
64
- tx : TransactionResponse
65
- ) : Operation [ ] => {
66
- const { sender, recipient, amount } = tx . stx_transfers [ 0 ] ;
67
- const { tx_id, fee_rate, block_height, burn_block_time, token_transfer } = tx . tx ;
68
- const { memo : memoHex } = token_transfer ;
69
-
70
- const ops : Operation [ ] = [ ] ;
71
-
72
- const date = new Date ( burn_block_time * 1000 ) ;
73
- const value = new BigNumber ( amount || "0" ) ;
74
- const feeToUse = new BigNumber ( fee_rate || "0" ) ;
75
-
76
- const isSending = address === sender ;
77
- const isReceiving = address === recipient ;
78
-
79
- const memo = Buffer . from ( memoHex . substring ( 2 ) , "hex" ) . toString ( ) . replaceAll ( "\x00" , "" )
80
-
81
- if ( isSending ) {
82
- ops . push ( {
83
- id : encodeOperationId ( accountID , tx_id , "OUT" ) ,
84
- hash : tx_id ,
85
- type : "OUT" ,
86
- value : value . plus ( feeToUse ) ,
87
- fee : feeToUse ,
88
- blockHeight : block_height ,
89
- blockHash : null ,
90
- accountId : accountID ,
91
- senders : [ sender ] ,
92
- recipients : [ recipient ] ,
93
- date,
94
- extra : {
95
- memo
96
- }
97
- } ) ;
98
- }
99
-
100
- if ( isReceiving ) {
101
- ops . push ( {
102
- id : encodeOperationId ( accountID , tx_id , "IN" ) ,
103
- hash : tx_id ,
104
- type : "IN" ,
105
- value,
106
- fee : feeToUse ,
107
- blockHeight : block_height ,
108
- blockHash : null ,
109
- accountId : accountID ,
110
- senders : [ sender ] ,
111
- recipients : [ recipient ] ,
112
- date,
113
- extra : {
114
- memo
115
- }
116
- } ) ;
117
- }
118
-
119
- return ops ;
120
- } ;
63
+ export const mapTxToOps =
64
+ ( accountID , { address } : AccountShapeInfo ) =>
65
+ ( tx : TransactionResponse ) : Operation [ ] => {
66
+ const { sender, recipient, amount } = tx . stx_transfers [ 0 ] ;
67
+ const { tx_id, fee_rate, block_height, burn_block_time, token_transfer } =
68
+ tx . tx ;
69
+ const { memo : memoHex } = token_transfer ;
70
+
71
+ const ops : Operation [ ] = [ ] ;
72
+
73
+ const date = new Date ( burn_block_time * 1000 ) ;
74
+ const value = new BigNumber ( amount || "0" ) ;
75
+ const feeToUse = new BigNumber ( fee_rate || "0" ) ;
76
+
77
+ const isSending = address === sender ;
78
+ const isReceiving = address === recipient ;
79
+
80
+ const memo = Buffer . from ( memoHex . substring ( 2 ) , "hex" )
81
+ . toString ( )
82
+ . replaceAll ( "\x00" , "" ) ;
83
+
84
+ if ( isSending ) {
85
+ ops . push ( {
86
+ id : encodeOperationId ( accountID , tx_id , "OUT" ) ,
87
+ hash : tx_id ,
88
+ type : "OUT" ,
89
+ value : value . plus ( feeToUse ) ,
90
+ fee : feeToUse ,
91
+ blockHeight : block_height ,
92
+ blockHash : null ,
93
+ accountId : accountID ,
94
+ senders : [ sender ] ,
95
+ recipients : [ recipient ] ,
96
+ date,
97
+ extra : {
98
+ memo,
99
+ } ,
100
+ } ) ;
101
+ }
102
+
103
+ if ( isReceiving ) {
104
+ ops . push ( {
105
+ id : encodeOperationId ( accountID , tx_id , "IN" ) ,
106
+ hash : tx_id ,
107
+ type : "IN" ,
108
+ value,
109
+ fee : feeToUse ,
110
+ blockHeight : block_height ,
111
+ blockHash : null ,
112
+ accountId : accountID ,
113
+ senders : [ sender ] ,
114
+ recipients : [ recipient ] ,
115
+ date,
116
+ extra : {
117
+ memo,
118
+ } ,
119
+ } ) ;
120
+ }
121
+
122
+ return ops ;
123
+ } ;
121
124
122
- export const getAccountShape : GetAccountShape = async info => {
125
+ export const getAccountShape : GetAccountShape = async ( info ) => {
123
126
const { initialAccount, address, currency, rest = { } , derivationMode } = info ;
124
127
125
128
const publicKey = reconciliatePublicKey ( rest . publicKey , initialAccount ) ;
0 commit comments