@@ -2,6 +2,7 @@ import { createAction } from '@reduxjs/toolkit';
22
33import {
44 localFirstToBip329 ,
5+ selectAccountLabel ,
56 selectAddressLabels ,
67 selectIsLocalFirstStorageEnabled ,
78 selectOutputLabels ,
@@ -11,6 +12,7 @@ import { triggerWebDownloadFile } from '@suite-common/suite-utils';
1112import { notificationsActions } from '@suite-common/toast-notifications' ;
1213import { selectDevices , selectSelectedDevice } from '@suite-common/wallet-core' ;
1314import { Account } from '@suite-common/wallet-types' ;
15+ import { parseDeviceStaticSessionId } from '@suite-common/wallet-utils' ;
1416import { StaticSessionId } from '@trezor/connect' ;
1517import { createZip } from '@trezor/utils' ;
1618
@@ -19,6 +21,7 @@ import {
1921 selectLabelingDataForSelectedAccount ,
2022 selectSelectedProviderForLabels ,
2123} from 'src/reducers/suite/metadataReducer' ;
24+ import { selectSelectedAccount } from 'src/reducers/wallet/selectedAccountReducer' ;
2225import { Dispatch , GetState } from 'src/types/suite' ;
2326import {
2427 AccountLabels ,
@@ -210,8 +213,17 @@ export const exportMetadataToBip329File = createThunk<void, void, void>(
210213 return Promise . resolve ( ) ;
211214 }
212215
216+ const selectedAccount = selectSelectedAccount ( getState ( ) ) ;
217+
218+ let accountLabel : string | undefined ;
213219 let labelsToExport : Bip329Label [ ] = [ ] ;
214220 if ( isLocalFirstStorageEnabled ) {
221+ const localFirstAccountLabel = selectAccountLabel ( {
222+ state : getState ( ) ,
223+ walletDescriptor : parseDeviceStaticSessionId ( staticSessionId ) . walletDescriptor ,
224+ accountKey : selectedAccount ! . key ,
225+ } ) ;
226+ accountLabel = localFirstAccountLabel || '' ;
215227 const localFirstOutputLabels = selectOutputLabels ( getState ( ) , staticSessionId ) ;
216228 const localFirstAddressLabels = selectAddressLabels ( {
217229 state : getState ( ) ,
@@ -225,16 +237,20 @@ export const exportMetadataToBip329File = createThunk<void, void, void>(
225237 } ) ;
226238 } else {
227239 const labelForSelectedAccount = selectLabelingDataForSelectedAccount ( getState ( ) ) ;
240+ accountLabel = labelForSelectedAccount ?. accountLabel ;
228241 labelsToExport = slip15ToBip329 ( labelForSelectedAccount as AccountLabels ) ;
229242 }
230243
244+ // Using label of the account, if not label then the default one like "Bitcoin #1".
245+ const filename = `${ accountLabel || selectedAccount ?. accountLabel || 'trezor_suite_labels' } .jsonl` ;
246+
231247 try {
232248 // Maps each object to its JSON string representation
233249 const jsonlString = labelsToExport . map ( obj => JSON . stringify ( obj ) ) . join ( '\n' ) ;
234250
235251 const blob = new Blob ( [ jsonlString ] , { type : 'application/jsonl' } ) ;
236252
237- triggerWebDownloadFile ( blob , 'suite_labels_export.jsonl' ) ;
253+ triggerWebDownloadFile ( blob , filename ) ;
238254 } catch {
239255 dispatch (
240256 notificationsActions . addToast ( {
0 commit comments