1- import { EBoostType , IBoostedTransactions } from 'beignet' ;
1+ import { EBoostType , IBoostedTransactions , Wallet as TWallet } from 'beignet' ;
22
33import { getActivityStore , getWalletStore } from '../store/helpers' ;
44import { IActivityItem , TOnchainActivityItem } from '../store/types/activity' ;
55import { TWalletName } from '../store/types/wallet' ;
66import { EAvailableNetwork } from './networks' ;
77import {
8- getOnChainWallet ,
8+ getOnChainWalletAsync ,
9+ // getOnChainWallet,
910 getSelectedNetwork ,
1011 getSelectedWallet ,
1112} from './wallet' ;
@@ -30,18 +31,21 @@ export const getBoostedTransactions = ({
3031
3132/**
3233 * Returns an array of parents for a boosted transaction id.
34+ * @param {TWallet } wallet
3335 * @param {string } txId
3436 * @param {IBoostedTransactions } [boostedTransactions]
3537 * @returns {string[] }
3638 */
3739export const getBoostedTransactionParents = ( {
40+ wallet,
3841 txId,
3942 boostedTransactions,
4043} : {
44+ wallet : TWallet ;
4145 txId : string ;
4246 boostedTransactions ?: IBoostedTransactions ;
4347} ) : string [ ] => {
44- return getOnChainWallet ( ) . getBoostedTransactionParents ( {
48+ return wallet . getBoostedTransactionParents ( {
4549 txid : txId ,
4650 boostedTransactions,
4751 } ) ;
@@ -57,11 +61,13 @@ export const getBoostedTransactionParents = ({
5761 * @returns {boolean }
5862 */
5963export const hasBoostedParents = ( {
64+ wallet,
6065 txId,
6166 boostedTransactions,
6267 selectedWallet = getSelectedWallet ( ) ,
6368 selectedNetwork = getSelectedNetwork ( ) ,
6469} : {
70+ wallet : TWallet ;
6571 txId : string ;
6672 boostedTransactions ?: IBoostedTransactions ;
6773 selectedWallet ?: TWalletName ;
@@ -74,6 +80,7 @@ export const hasBoostedParents = ({
7480 } ) ;
7581 }
7682 const boostedParents = getBoostedTransactionParents ( {
83+ wallet,
7784 txId,
7885 boostedTransactions,
7986 } ) ;
@@ -89,7 +96,7 @@ export const hasBoostedParents = ({
8996 * @param {EAvailableNetwork } [selectedNetwork]
9097 * @returns {TOnchainActivityItem|undefined }
9198 */
92- export const getRootParentActivity = ( {
99+ const getRootParentActivity = async ( {
93100 txId,
94101 items,
95102 boostedTransactions,
@@ -101,14 +108,16 @@ export const getRootParentActivity = ({
101108 boostedTransactions ?: IBoostedTransactions ;
102109 selectedWallet ?: TWalletName ;
103110 selectedNetwork ?: EAvailableNetwork ;
104- } ) : TOnchainActivityItem | undefined => {
111+ } ) : Promise < TOnchainActivityItem | undefined > => {
112+ const wallet = await getOnChainWalletAsync ( ) ;
105113 if ( ! boostedTransactions ) {
106114 boostedTransactions = getBoostedTransactions ( {
107115 selectedWallet,
108116 selectedNetwork,
109117 } ) ;
110118 }
111119 const boostedParents = getBoostedTransactionParents ( {
120+ wallet,
112121 txId,
113122 boostedTransactions,
114123 } ) ;
@@ -147,7 +156,7 @@ export const getParentsActivity = ({
147156 * @param {EAvailableNetwork } [selectedNetwork]
148157 * @returns {TOnchainActivityItem[] }
149158 */
150- export const formatBoostedActivityItems = ( {
159+ export const formatBoostedActivityItems = async ( {
151160 items,
152161 boostedTransactions,
153162 selectedWallet,
@@ -157,18 +166,18 @@ export const formatBoostedActivityItems = ({
157166 boostedTransactions : IBoostedTransactions ;
158167 selectedWallet : TWalletName ;
159168 selectedNetwork : EAvailableNetwork ;
160- } ) : TOnchainActivityItem [ ] => {
169+ } ) : Promise < TOnchainActivityItem [ ] > => {
161170 const formattedItems : TOnchainActivityItem [ ] = [ ] ;
162171
163- items . forEach ( ( item ) => {
172+ for ( const item of items ) {
164173 const { txId } = item ;
165174
166175 // if boosted tx don't add for now
167176 if ( txId in boostedTransactions ) {
168- return ;
177+ continue ;
169178 }
170179
171- const rootParent = getRootParentActivity ( {
180+ const rootParent = await getRootParentActivity ( {
172181 txId,
173182 items,
174183 boostedTransactions,
@@ -179,18 +188,18 @@ export const formatBoostedActivityItems = ({
179188 // if we can't find a parent tx leave as is
180189 if ( ! rootParent ) {
181190 formattedItems . push ( item ) ;
182- return ;
191+ continue ;
183192 }
184193
185194 const parentBoostType = boostedTransactions [ rootParent . txId ] . type ;
186195
187196 // if it's an RBF tx leave as is, only mark as boosted
188197 if ( parentBoostType === EBoostType . rbf ) {
189198 formattedItems . push ( { ...item , isBoosted : true } ) ;
190- return ;
199+ continue ;
191200 }
192201
193- const value = calculateBoostTransactionValue ( {
202+ const value = await calculateBoostTransactionValue ( {
194203 currentActivityItem : item ,
195204 items,
196205 boostedTransactions,
@@ -207,7 +216,7 @@ export const formatBoostedActivityItems = ({
207216 address : rootParent . address ,
208217 isBoosted : true ,
209218 } ) ;
210- } ) ;
219+ }
211220
212221 return formattedItems ;
213222} ;
@@ -220,7 +229,7 @@ export const formatBoostedActivityItems = ({
220229 * @param {IBoostedTransactions } boostedTransactions
221230 * @returns {number }
222231 */
223- export const calculateBoostTransactionValue = ( {
232+ export const calculateBoostTransactionValue = async ( {
224233 currentActivityItem,
225234 items,
226235 boostedTransactions,
@@ -230,14 +239,14 @@ export const calculateBoostTransactionValue = ({
230239 items : TOnchainActivityItem [ ] ;
231240 boostedTransactions : IBoostedTransactions ;
232241 includeFee ?: boolean ;
233- } ) : number => {
242+ } ) : Promise < number > => {
234243 const boostedTransaction = Object . values ( boostedTransactions ) . find (
235244 ( tx ) => tx . childTransaction === currentActivityItem . txId ,
236245 ) ;
237246 if ( ! boostedTransaction ) {
238247 return currentActivityItem . value ;
239248 }
240- const rootParent = getRootParentActivity ( {
249+ const rootParent = await getRootParentActivity ( {
241250 txId : currentActivityItem . txId ,
242251 items,
243252 boostedTransactions,
0 commit comments