Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/useWallet.js
Show All 13 Lines | import { | ||||
getWalletBalanceFromUtxos, | getWalletBalanceFromUtxos, | ||||
toHash160, | toHash160, | ||||
} from 'utils/cashMethods'; | } from 'utils/cashMethods'; | ||||
import { | import { | ||||
isValidCashtabSettings, | isValidCashtabSettings, | ||||
isValidCashtabCache, | isValidCashtabCache, | ||||
isValidContactList, | isValidContactList, | ||||
parseInvalidSettingsForMigration, | parseInvalidSettingsForMigration, | ||||
validateMnemonicWordList, | |||||
} from 'utils/validation'; | } from 'utils/validation'; | ||||
import localforage from 'localforage'; | import localforage from 'localforage'; | ||||
import { currency } from 'components/Common/Ticker'; | import { currency } from 'components/Common/Ticker'; | ||||
import { | import { | ||||
xecReceivedNotification, | xecReceivedNotification, | ||||
xecReceivedNotificationWebsocket, | xecReceivedNotificationWebsocket, | ||||
eTokenReceivedNotification, | eTokenReceivedNotification, | ||||
} from 'components/Common/Notifications'; | } from 'components/Common/Notifications'; | ||||
▲ Show 20 Lines • Show All 803 Lines • ▼ Show 20 Lines | const createWallet = async importMnemonic => { | ||||
`Error setting wallet to savedWallets indexedDb in createWallet()`, | `Error setting wallet to savedWallets indexedDb in createWallet()`, | ||||
); | ); | ||||
console.log(err); | console.log(err); | ||||
} | } | ||||
return wallet; | return wallet; | ||||
}; | }; | ||||
const validateMnemonic = (mnemonic, wordlist = bip39.wordlists.english) => { | const validateMnemonic = (mnemonic, wordlist = bip39.wordlists.english) => { | ||||
let mnemonicTestOutput; | |||||
// temporary validation of wordlist exclusion | |||||
// to be removed in next diff in stack | |||||
console.log('english: ' + bip39.wordlists.english); | |||||
if ( | |||||
!bip39.wordlists.japanese && | |||||
!bip39.wordlists.spanish && | |||||
!bip39.wordlists.italian && | |||||
!bip39.wordlists.french && | |||||
!bip39.wordlists.korean && | |||||
!bip39.wordlists.czech && | |||||
!bip39.wordlists.portuguese && | |||||
!bip39.wordlists.chinese_traditional | |||||
) { | |||||
console.log( | |||||
'bip39 wordlist is excluding japanese, spanish, italian, french, korean, czech, portuguese and chinese', | |||||
); | |||||
} | |||||
try { | try { | ||||
mnemonicTestOutput = validateMnemonicWordList(mnemonic, wordlist); | if (!mnemonic || !wordlist) return false; | ||||
if (mnemonicTestOutput === 'Valid mnemonic') { | // Preprocess the words | ||||
return true; | const words = mnemonic.split(' '); | ||||
} else { | // Detect blank phrase | ||||
return false; | if (words.length === 0) return false; | ||||
} | |||||
// Check the words are valid | |||||
return bip39.validateMnemonic(mnemonic, wordlist); | |||||
} catch (err) { | } catch (err) { | ||||
console.log(err); | console.log(err); | ||||
return false; | return false; | ||||
} | } | ||||
}; | }; | ||||
// Parse chronik ws message for incoming tx notifications | // Parse chronik ws message for incoming tx notifications | ||||
const processChronikWsMsg = async (msg, wallet, fiatPrice) => { | const processChronikWsMsg = async (msg, wallet, fiatPrice) => { | ||||
▲ Show 20 Lines • Show All 634 Lines • Show Last 20 Lines |