Skip to content

Commit

Permalink
fix: await that wasm initialization before creating a wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
clangenb committed Apr 29, 2024
1 parent d325616 commit 7a110f0
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions components/CreateWalletTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<script setup lang="ts">
import {Keyring} from '@polkadot/keyring'
import {mnemonicGenerate, mnemonicToMiniSecret} from '@polkadot/util-crypto'
import {cryptoWaitReady, mnemonicGenerate, mnemonicToMiniSecret} from '@polkadot/util-crypto'
import {u8aToHex} from "@polkadot/util";
import { useAccount } from '@/store/account.ts'
import { useRouter } from 'vue-router';
Expand All @@ -32,20 +32,21 @@ const router = useRouter();
const accountStore = useAccount()
const emit = defineEmits(['change-tab'])
const createWallet = () => {
const createWallet = async () => {
console.log('creating fresh wallet');
await cryptoWaitReady()
const generatedMnemonic = mnemonicGenerate();
const localKeyring = new Keyring({type: 'sr25519', ss58Format: 42});
const newAccount = localKeyring.addFromMnemonic(generatedMnemonic, {name: 'fresh'});
const seed = mnemonicToMiniSecret(generatedMnemonic);
const privateKeyHex = u8aToHex(seed);
console.log(`Private Key in Hex: ${privateKeyHex}`);
// change url to contain new seed to allow bookmarking
router.push({
query:{ seed: privateKeyHex}
await router.push({
query: {seed: privateKeyHex}
})
accountStore.setAccount(newAccount)
emit('change-tab',1);
emit('change-tab', 1);
};
onMounted(() => {
Expand Down

0 comments on commit 7a110f0

Please sign in to comment.