diff --git a/packages/apps/public/locales/en/app-addresses.json b/packages/apps/public/locales/en/app-addresses.json index a30a29c1013d..efc104db3470 100644 --- a/packages/apps/public/locales/en/app-addresses.json +++ b/packages/apps/public/locales/en/app-addresses.json @@ -1,17 +1,26 @@ { "Add an address": "Add an address", "Add contact": "Add contact", + "Export": "Export", "Forget this address": "Forget this address", + "Import": "Import", + "Import file": "Import file", + "Importing": "Importing", "My contacts": "My contacts", "Save": "Save", + "Success": "Success", "address": "address", "address created": "address created", "address edited": "address edited", "address forgotten": "address forgotten", "contacts": "contacts", + "file content error": "file content error", + "file error": "file error", "filter by name or tags": "filter by name or tags", "name": "name", "new address": "new address", + "no account imported": "no account imported", "no addresses saved yet, add any existing address": "no addresses saved yet, add any existing address", + "no file choosen": "no file choosen", "send": "send" } \ No newline at end of file diff --git a/packages/apps/public/locales/en/translation.json b/packages/apps/public/locales/en/translation.json index 63a19f772b00..60c3ad8204b7 100644 --- a/packages/apps/public/locales/en/translation.json +++ b/packages/apps/public/locales/en/translation.json @@ -331,6 +331,7 @@ "Image": "", "Import": "", "Import Success": "", + "Import file": "", "Import files": "", "Importing": "", "In calculating the election outcome, this prioritized vote ordering will be used to determine the final score for the candidates.": "", @@ -747,6 +748,7 @@ "Submit {{queueSize}} items": "", "Submitted at": "", "Subscan Links": "", + "Success": "", "Sudo access": "", "Sudo key": "", "Supply a JSON file with the list of signatories.": "", @@ -1588,7 +1590,9 @@ "next burn": "", "next index": "", "no": "", + "no account imported": "", "no addresses saved yet, add any existing address": "", + "no file choosen": "", "no name": "", "no peers connected": "", "no unapplied slashes found": "", diff --git a/packages/page-addresses/src/Contacts/Export.tsx b/packages/page-addresses/src/Contacts/Export.tsx new file mode 100644 index 000000000000..acb2f118ab5f --- /dev/null +++ b/packages/page-addresses/src/Contacts/Export.tsx @@ -0,0 +1,49 @@ +// Copyright 2017-2025 @polkadot/app-addresses authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { SortedAddress } from './types.js'; + +import FileSaver from 'file-saver'; +import React, { useCallback } from 'react'; + +import { Button } from '@polkadot/react-components'; +import { keyring } from '@polkadot/ui-keyring'; + +import { useTranslation } from '../translate.js'; + +interface Props { + sortedAddresses?: SortedAddress[] +} + +function Export ({ sortedAddresses }: Props): React.ReactElement { + const { t } = useTranslation(); + + const onExport = useCallback(() => { + const accounts = sortedAddresses?.map(({ address, isFavorite }) => { + const account = keyring.getAddress(address); // get account info + + return { address, isFavorite, name: account?.meta.name || address }; + }); + + /** **************** Export accounts as JSON ******************/ + + const blob = new Blob([JSON.stringify(accounts, null, 2)], { type: 'application/json; charset=utf-8' }); + + // eslint-disable-next-line deprecation/deprecation + FileSaver.saveAs(blob, `batch_exported_address_book_${new Date().getTime()}.json`); + + /** ********************* ************** ************************/ + }, [sortedAddresses]); + + return sortedAddresses?.length + ? ( +