import { Answer, WalletTypeValue } from '../../models/choice' import { generateNewWallet } from '../../templates/wallet/generate_new' import { importWallet } from '../../templates/wallet/import' import { showInfo } from '../../utils/logger.util' import { walletBackupConfirm } from './backup_confirm.question' import { checkSeed } from './seed_check' import { walletConfirm } from './wallet_confirm.question' import { walletImportQuestion } from './wallet_import.question' import { walletQuestion } from './wallet_type.question' import { checkAnswerYes } from '../../utils/checker.util' export const WalletCreation = async () => { let seedPhrase = '', walletAddress = '', valid = false const walletType: Answer = await walletQuestion() if (walletType.walletType === WalletTypeValue.New) { const [keyPair, seed] = await generateNewWallet() while (!valid) { // generate seed phrase and wait confirmation that user backed up it const confirm: Answer = await walletBackupConfirm(seed) valid = checkAnswerYes(confirm.walletBackupConfirm) if (valid) { await checkSeed(seed) seedPhrase = seed walletAddress = keyPair.address showInfo('Seed phrase confirmed.') showInfo(`Address of your wallet: ${keyPair.address}`) break } } } else if (walletType.walletType === WalletTypeValue.Existing) { while (!valid) { // import key and wait confirmation from user that address is correct const walletImport = await walletImportQuestion() const [keyPair, ok] = importWallet(walletImport.walletImportPayload) if (!ok || !keyPair) { continue } const confirmations = await walletConfirm(keyPair.address) valid = checkAnswerYes(confirmations.walletConfirm) if (valid) { seedPhrase = walletImport.walletImportPayload walletAddress = keyPair.address break } } } showInfo('Wallet created. Generating config...') return { seedPhrase, walletAddress, } }