// Copyright 2017-2021 @polkadot/example-vue authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { Prefix } from '@polkadot/util-crypto/address/types'; import Vue, { VNode } from 'vue'; import { keyring } from '@polkadot/ui-keyring'; import { settings } from '@polkadot/ui-settings'; import { cryptoWaitReady, mnemonicGenerate } from '@polkadot/util-crypto'; import Identicon from '@polkadot/vue-identicon'; interface Account { address: string; phrase: string; } interface Data extends Account { ss58Format: Prefix; ss58Options: { text: string; value: string | number }[]; } const ss58Options = settings.availablePrefixes.filter((_, index): boolean => index !== 0); function generateAccount (ss58Format: Prefix = 42): Account { const phrase = mnemonicGenerate(12); const { address } = keyring.createFromUri(phrase); return { address: keyring.encodeAddress(address, ss58Format), phrase }; } const Example = Vue.extend({ components: { Identicon }, data: function (): Data { return { ...generateAccount(), ss58Format: 42, ss58Options }; }, methods: { onClickNew: function (): void { const { address, phrase } = generateAccount(this.ss58Format); this.address = address; this.phrase = phrase; } }, name: 'Example', template: `