Skip to content

Commit 97e73ec

Browse files
committed
feat(suite): add account label to file name
1 parent a0f6ef1 commit 97e73ec

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

packages/suite/src/actions/suite/metadataActions.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createAction } from '@reduxjs/toolkit';
22

33
import {
44
localFirstToBip329,
5+
selectAccountLabel,
56
selectAddressLabels,
67
selectIsLocalFirstStorageEnabled,
78
selectOutputLabels,
@@ -11,6 +12,7 @@ import { triggerWebDownloadFile } from '@suite-common/suite-utils';
1112
import { notificationsActions } from '@suite-common/toast-notifications';
1213
import { selectDevices, selectSelectedDevice } from '@suite-common/wallet-core';
1314
import { Account } from '@suite-common/wallet-types';
15+
import { parseDeviceStaticSessionId } from '@suite-common/wallet-utils';
1416
import { StaticSessionId } from '@trezor/connect';
1517
import { 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';
2225
import { Dispatch, GetState } from 'src/types/suite';
2326
import {
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

Comments
 (0)