You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.2 KiB

6 years ago
import 'babel-polyfill';
import whenDomReady from 'when-dom-ready';
import dogeSeed from '../';
import noUiSlider from 'nouislider';
6 years ago
const bitsToWords = {
128: 12,
160: 15,
192: 18,
224: 21,
256: 24
};
6 years ago
const main = async () => {
await whenDomReady();
const seedText = document.querySelector('.seed-text');
const regenerateSeedButton = document.querySelector('.regenerate-seed');
6 years ago
const bitSlider = noUiSlider.create(document.querySelector('.bit-slider'), {
range: {min: 128, max: 256},
step: 32,
start: 256,
pips: {
mode: 'steps',
density: 1,
format: {to: bits => bitsToWords[bits]},
filter: (value, step) => step === 0 ? -1 : 1
}
});
const generateSeed = () => {
const bits = Number(bitSlider.get());
const seedPhraseWords = dogeSeed(bits).split(' ');
const wrappedSeedPhrase = seedPhraseWords.map(word => `<span>${word}</span>`).join(' ');
const wordCount = seedPhraseWords.length;
seedText.dataset.wordCount = wordCount;
seedText.innerHTML = wrappedSeedPhrase;
};
6 years ago
regenerateSeedButton.addEventListener('click', generateSeed);
bitSlider.on('update', generateSeed);
6 years ago
generateSeed();
};
main();