diff --git a/src/components/contacts-list.js b/src/components/contacts-list.js index 06e7b00..8b2f842 100644 --- a/src/components/contacts-list.js +++ b/src/components/contacts-list.js @@ -38,13 +38,13 @@ const initialState = { `, - content: state => html` + content: async state => html` ${state.header(state)}
${ state.contacts.length > 0 - ? state.contacts.map(c => state.item(c)).join('') + ? (await Promise.all(state.contacts.map(async c => await state.item(c)))).join('') : '' } ${ @@ -55,7 +55,7 @@ const initialState = { ${state.footer(state)} `, - item: c => { + item: async c => { // console.warn('contact list item', c) if ('string' === typeof c) { return html` @@ -109,7 +109,7 @@ const initialState = { return html` - ${getAvatar(c)} + ${await getAvatar(c)}

${itemAlias}

${itemName}
@@ -181,7 +181,7 @@ export async function setupContactsList( section.id = state.slugs.section section.classList.add(state.placement || '') - section.innerHTML = state.content(state) + section.innerHTML = await state.content(state) function addListener( node, @@ -228,7 +228,7 @@ export async function setupContactsList( await restate(state, renderState) section.id = state.slugs.section - section.innerHTML = state.content(state) + section.innerHTML = await state.content(state) removeAllListeners() addListeners() diff --git a/src/components/dialog.js b/src/components/dialog.js index 4882d29..f116689 100644 --- a/src/components/dialog.js +++ b/src/components/dialog.js @@ -1,5 +1,14 @@ import { lit as html } from '../helpers/lit.js' -import { formDataEntries } from '../helpers/utils.js' +import { + formDataEntries, + envoy, +} from '../helpers/utils.js' + +let modal = envoy( + { + rendered: {}, + }, +) let _handlers = [] @@ -13,6 +22,7 @@ const initialState = { closeTxt: 'X', closeAlt: `Close`, placement: 'center', + modal, rendered: null, responsive: true, delay: 500, @@ -28,7 +38,7 @@ const initialState = { } `, - content: state => html` + content: async state => html` ${state.header(state)}
@@ -172,10 +182,20 @@ const initialState = { } else { resolve('cancel') } + // console.log( + // 'DIALOG handleClose', + // modal.rendered[state.slugs.dialog], + // ) setTimeout(t => { - state.rendered = null + modal.rendered[state.slugs.dialog] = null event?.target?.remove() + // console.log( + // 'DIALOG handleClose setTimeout', + // state.delay, + // // modal.rendered[state.slugs.dialog], + // modal.rendered, + // ) }, state.delay) }, handleSubmit: state => event => { @@ -214,7 +234,7 @@ const initialState = { }, } -export function setupDialog( +export async function setupDialog( el, setupState = {} ) { let state = { @@ -260,7 +280,7 @@ export function setupDialog( form.name = `${state.slugs.form}` form.method = 'dialog' - form.innerHTML = state.content(state) + form.innerHTML = await state.content(state) dialog.insertAdjacentElement( 'afterbegin', @@ -281,16 +301,19 @@ export function setupDialog( resolve, reject, ) { - addListener( - dialog, - 'close', - state.events.handleClose(state, resolve, reject), - ) - addListener( - dialog, - 'click', - state.events.handleClick(state), - ) + if (resolve && reject) { + addListener( + dialog, + 'close', + state.events.handleClose(state, resolve, reject), + ) + + addListener( + dialog, + 'click', + state.events.handleClick(state), + ) + } addListener( form, @@ -302,29 +325,30 @@ export function setupDialog( 'change', state.events.handleChange(state), ) - let updrop = form.querySelector('.updrop') - if (updrop) { + // let updrop = form.querySelector('.updrop') + // state.elements.updrop = updrop + // if (updrop) { addListener( - updrop, + form, 'drop', state.events.handleDrop(state), ) addListener( - updrop, + form, 'dragover', state.events.handleDragOver(state), ) addListener( - updrop, + form, 'dragend', state.events.handleDragEnd(state), ) addListener( - updrop, + form, 'dragleave', state.events.handleDragLeave(state), ) - } + // } addListener( form, 'input', @@ -342,9 +366,14 @@ export function setupDialog( ) } + state.addListeners = addListeners + function removeAllListeners( targets = [dialog,form], ) { + if (state.elements.updrop) { + targets.push(state.elements.updrop) + } _handlers = _handlers .filter(({ node, event, handler, capture }) => { if (targets.includes(node)) { @@ -382,13 +411,13 @@ export function setupDialog( dialog.id = state.slugs.dialog form.name = `${state.slugs.form}` - form.innerHTML = state.content(state) + form.innerHTML = await state.content(state) - // console.log('DIALOG RENDER', state, position, state.slugs.dialog) + // console.log('DIALOG RENDER', state, position, state.slugs.dialog, modal.rendered) - if (!state.rendered) { + if (!modal.rendered[state.slugs.dialog]) { el.insertAdjacentElement(position, dialog) - state.rendered = dialog + modal.rendered[state.slugs.dialog] = dialog } state.events.handleRender(state) @@ -401,6 +430,7 @@ export function setupDialog( show: (callback) => new Promise((resolve, reject) => { removeAllListeners() addListeners(resolve, reject) + // console.log('dialog show', dialog) dialog.show() state.events.handleShow?.(state) callback?.() @@ -408,6 +438,7 @@ export function setupDialog( showModal: (callback) => new Promise((resolve, reject) => { removeAllListeners() addListeners(resolve, reject) + // console.log('dialog showModal', dialog) dialog.showModal() state.events.handleShow?.(state) callback?.() diff --git a/src/helpers/utils.js b/src/helpers/utils.js index 89410ed..1b8ce98 100644 --- a/src/helpers/utils.js +++ b/src/helpers/utils.js @@ -831,7 +831,29 @@ export function getBackgroundColor(stringInput) { return `hsl(${stringUniqueHash % 360}, 100%, 67%)`; } -export function getAvatar(c) { +export async function getAvatarUrl( + email, + size = 48, + rating = 'pg', + srv = 'gravatar', +) { + let emailSHA = await sha256(email || '') + + if (srv === 'gravatar') { + return `https://gravatar.com/avatar/${ + emailSHA + }?s=${size}&r=${rating}&d=retro` + } + if (srv === 'libravatar') { + return `https://seccdn.libravatar.org/avatar/${ + emailSHA + }?s=${size}&r=${rating}&d=retro` + } + + return '' +} + +export async function getAvatar(c) { let initials = c?.info?.name?. split(' ').map(n => n[0]).slice(0,3).join('') || '' @@ -848,11 +870,11 @@ export function getAvatar(c) { } // Gravatar - // if (c?.info?.email) { - // avStr += `color:transparent;background-image:url(https://gravatar.com/avatar/${ - // await sha256(c.info.email) - // }?s=48&r=pg&d=retro);` - // } + if (c?.info?.email) { + avStr += `color:transparent;background-image:url(${ + await getAvatarUrl(c.info.email) + });` + } return `${avStr}">${initials}
` } diff --git a/src/main.js b/src/main.js index 57020a3..026aac0 100644 --- a/src/main.js +++ b/src/main.js @@ -185,7 +185,7 @@ let contactsList = await setupContactsList( if (!contactData.outgoing) { // Finish Pairing let contactName = contactData?.info?.name || 'Contact' - appDialogs.addContact.render( + await appDialogs.addContact.render( { name: `Finish Pairing with ${contactName}`, wallet: shareAccount, @@ -197,7 +197,7 @@ let contactsList = await setupContactsList( appDialogs.addContact.showModal() } else { // Edit Contact - appDialogs.editContact.render( + await appDialogs.editContact.render( { wallet, account: appState.account, @@ -301,7 +301,7 @@ let contactsList = await setupContactsList( appState.contacts.push(newContact) - contactsList.render( + await contactsList.render( appState.contacts.sort(sortContactsByAlias) ) @@ -311,7 +311,7 @@ let contactsList = await setupContactsList( ) } - appDialogs.addContact.render( + await appDialogs.addContact.render( { name: 'Add a New Contact', wallet: shareAccount, @@ -394,90 +394,90 @@ async function main() { } ) - appDialogs.walletEncrypt = walletEncryptRig({ + appDialogs.walletEncrypt = await walletEncryptRig({ setupDialog, appDialogs, appState, mainApp, wallet, wallets, bodyNav, dashBalance, }) - appDialogs.walletDecrypt = walletDecryptRig({ + appDialogs.walletDecrypt = await walletDecryptRig({ setupDialog, appDialogs, appState, mainApp, importFromJson, wallets, decryptKeystore, getUserInfo, store, deriveWalletData, }) - appDialogs.walletBackup = walletBackupRig({ + appDialogs.walletBackup = await walletBackupRig({ mainApp, wallet, wallets, setupDialog, appDialogs, appState, store, exportWalletData, saveJsonToFile, localForageBaseCfg, }) - appDialogs.phraseBackup = phraseBackupRig({ + appDialogs.phraseBackup = await phraseBackupRig({ mainApp, wallets, setupDialog, appDialogs, }) - appDialogs.phraseGenerate = phraseGenerateRig({ + appDialogs.phraseGenerate = await phraseGenerateRig({ setupDialog, appDialogs, appState, mainApp, wallet, wallets, store, deriveWalletData, generateWalletData, }) - appDialogs.phraseImport = phraseImportRig({ + appDialogs.phraseImport = await phraseImportRig({ setupDialog, appDialogs, appState, store, mainApp, wallet, wallets, deriveWalletData, }) - appDialogs.onboard = onboardRig({ + appDialogs.onboard = await onboardRig({ mainApp, setupDialog, appDialogs, }) - appDialogs.addContact = addContactRig({ + appDialogs.addContact = await addContactRig({ setupDialog, updateAllFunds, appDialogs, appState, appTools, store, walletFunds, mainApp, wallet, userInfo, contactsList, }) - appDialogs.confirmAction = confirmActionRig({ + appDialogs.confirmAction = await confirmActionRig({ mainApp, setupDialog, appDialogs, appState, appTools, }) - appDialogs.confirmDelete = confirmDeleteRig({ + appDialogs.confirmDelete = await confirmDeleteRig({ mainApp, setupDialog, appDialogs, appState, appTools, store, userInfo, contactsList, }) - appDialogs.editContact = editContactRig({ + appDialogs.editContact = await editContactRig({ setupDialog, updateAllFunds, appDialogs, appState, appTools, store, walletFunds, mainApp, wallet, userInfo, contactsList, }) - appDialogs.editProfile = editProfileRig({ + appDialogs.editProfile = await editProfileRig({ mainApp, setupDialog, store, appState, appTools, bodyNav, }) - appDialogs.scanContact = scanContactRig({ + appDialogs.scanContact = await scanContactRig({ setupDialog, mainApp, }) - appDialogs.sendOrReceive = sendOrReceiveRig({ + appDialogs.sendOrReceive = await sendOrReceiveRig({ mainApp, appDialogs, appState, appTools, store, wallet, account: appState.account, walletFunds, setupDialog, deriveWalletData, createTx, getAddrsWithFunds, batchGenAcctAddrs, }) - appDialogs.sendConfirm = sendConfirmRig({ + appDialogs.sendConfirm = await sendConfirmRig({ mainApp, appDialogs, appState, appTools, store, userInfo, contactsList, walletFunds, setupDialog, deriveWalletData, getAddrsWithFunds, createTx, sendTx, }) - appDialogs.requestQr = requestQrRig({ + appDialogs.requestQr = await requestQrRig({ mainApp, setupDialog, }) - appDialogs.pairQr = pairQrRig({ + appDialogs.pairQr = await pairQrRig({ setupDialog, mainApp, wallet, userInfo, }) @@ -500,7 +500,7 @@ async function main() { name = 'Receive Funds' } - appDialogs.sendOrReceive.render({ + await appDialogs.sendOrReceive.render({ action: fde.intent, wallet, account: appState.account, @@ -593,7 +593,7 @@ async function main() { ) { sessionStorage.removeItem('encryptionPassword') - appDialogs.walletDecrypt.render({ wallet }) + await appDialogs.walletDecrypt.render({ wallet }) await appDialogs.walletDecrypt.showModal() } @@ -612,7 +612,7 @@ async function main() { ] if (!appState.phrase) { - appDialogs.onboard.render() + await appDialogs.onboard.render() await appDialogs.onboard.show() } else { wallet = await deriveWalletData(appState.phrase) @@ -718,14 +718,13 @@ async function main() { await getUserInfo() - appDialogs.editProfile.render( + await appDialogs.editProfile.render( { wallet, userInfo, }, 'afterend', ) - appDialogs.editProfile.showModal() } if (id === 'nav-backup') { @@ -735,7 +734,7 @@ async function main() { // @ts-ignore event.target?.closest?.('menu.user')?.classList?.toggle('hidden') - appDialogs.walletBackup.render( + await appDialogs.walletBackup.render( { wallet, wallets, @@ -751,7 +750,7 @@ async function main() { // @ts-ignore event.target?.closest?.('menu.user')?.classList?.toggle('hidden') - appDialogs.confirmAction.render({ + await appDialogs.confirmAction.render({ name: 'Confirm Wallet Lock', actionTxt: 'Lock it!', actionAlt: 'Lock the wallet', @@ -774,7 +773,7 @@ async function main() { // @ts-ignore event.target?.closest?.('menu.user')?.classList?.toggle('hidden') - appDialogs.confirmAction.render({ + await appDialogs.confirmAction.render({ name: 'Confirm Wallet Disconnect', actionTxt: 'Disconnect', actionAlt: 'Clear all wallet data stored in browser', diff --git a/src/rigs/add-contact.js b/src/rigs/add-contact.js index 554d2c5..26159ff 100644 --- a/src/rigs/add-contact.js +++ b/src/rigs/add-contact.js @@ -22,7 +22,7 @@ import { ALIAS_REGEX, } from '../helpers/constants.js' -export let addContactRig = (function (globals) { +export let addContactRig = (async function (globals) { 'use strict'; let { @@ -227,7 +227,7 @@ export let addContactRig = (function (globals) { return } - let addContact = setupDialog( + let addContact = await setupDialog( mainApp, { name: 'Add a New Contact', @@ -494,7 +494,7 @@ export let addContactRig = (function (globals) { console.log('scanContact', appDialogs.scanContact) if (fde?.intent === 'scan_new_contact') { - appDialogs.scanContact.render( + await appDialogs.scanContact.render( { wallet, }, diff --git a/src/rigs/confirm-action.js b/src/rigs/confirm-action.js index 9a0c2d9..a7996ad 100644 --- a/src/rigs/confirm-action.js +++ b/src/rigs/confirm-action.js @@ -3,7 +3,7 @@ import { formDataEntries, } from '../helpers/utils.js' -export let confirmActionRig = (function (globals) { +export let confirmActionRig = (async function (globals) { 'use strict'; let { @@ -11,7 +11,7 @@ export let confirmActionRig = (function (globals) { store, userInfo, contactsList, } = globals - let confirmAction = setupDialog( + let confirmAction = await setupDialog( mainApp, { name: 'Confirm', diff --git a/src/rigs/confirm-delete.js b/src/rigs/confirm-delete.js index d2bad60..218a5be 100644 --- a/src/rigs/confirm-delete.js +++ b/src/rigs/confirm-delete.js @@ -5,7 +5,7 @@ import { sortContactsByAlias, } from '../helpers/utils.js' -export let confirmDeleteRig = (function (globals) { +export let confirmDeleteRig = (async function (globals) { 'use strict'; let { @@ -13,7 +13,7 @@ export let confirmDeleteRig = (function (globals) { store, userInfo, contactsList, } = globals - let confirmDelete = setupDialog( + let confirmDelete = await setupDialog( mainApp, { name: 'Confirm Remove', diff --git a/src/rigs/edit-contact.js b/src/rigs/edit-contact.js index 9e63048..c13dabe 100644 --- a/src/rigs/edit-contact.js +++ b/src/rigs/edit-contact.js @@ -22,7 +22,7 @@ import { ALIAS_REGEX, } from '../helpers/constants.js' -export let editContactRig = (function (globals) { +export let editContactRig = (async function (globals) { 'use strict'; let { @@ -89,7 +89,7 @@ export let editContactRig = (function (globals) { ) }, 1000) - let editContact = setupDialog( + let editContact = await setupDialog( mainApp, { name: 'Edit Contact', @@ -155,12 +155,12 @@ export let editContactRig = (function (globals) { `, - content: state => html` + content: async state => html`
${state.header(state)}
- ${getAvatar(state.contact)} + ${await getAvatar(state.contact)}

@${state.contact?.alias || state.contact?.info?.preferred_username}

@@ -377,7 +377,7 @@ export let editContactRig = (function (globals) { event.target !== contactCard && contactCard?.contains(event.target) ) { - appDialogs.pairQr.render( + await appDialogs.pairQr.render( { name: `Pairing info for @${storedContact.alias}`, wallet: state.shareAccount, @@ -426,7 +426,7 @@ export let editContactRig = (function (globals) { if (['send','request'].includes(String(fde?.intent))) { editContact.close() - appDialogs.sendOrRequest.render({ + await appDialogs.sendOrReceive.render({ action: fde.intent, wallet: state.wallet, account: appState.account, @@ -434,13 +434,13 @@ export let editContactRig = (function (globals) { contacts: appState.contacts, to: `@${storedContact.alias}`, }) - appDialogs.sendOrRequest.showModal() + appDialogs.sendOrReceive.showModal() return; } if (fde?.intent === 'delete_contact') { - appDialogs.confirmDelete.render({ + await appDialogs.confirmDelete.render({ shareAccount: state.shareAccount, userInfo, contacts: appState.contacts, diff --git a/src/rigs/edit-profile.js b/src/rigs/edit-profile.js index 02952b0..2ff9133 100644 --- a/src/rigs/edit-profile.js +++ b/src/rigs/edit-profile.js @@ -13,7 +13,7 @@ import { ALIAS_REGEX, } from '../helpers/constants.js' -export let editProfileRig = (function (globals) { +export let editProfileRig = (async function (globals) { 'use strict'; let { @@ -21,7 +21,7 @@ export let editProfileRig = (function (globals) { appState, appTools, bodyNav, } = globals; - let editProfile = setupDialog( + let editProfile = await setupDialog( mainApp, { name: 'Edit Profile', diff --git a/src/rigs/onboard.js b/src/rigs/onboard.js index 1ffb5f5..899120f 100644 --- a/src/rigs/onboard.js +++ b/src/rigs/onboard.js @@ -3,14 +3,14 @@ import { formDataEntries, } from '../helpers/utils.js' -export let onboardRig = (function (globals) { +export let onboardRig = (async function (globals) { 'use strict'; let { mainApp, setupDialog, appDialogs, } = globals; - let onboard = setupDialog( + let onboard = await setupDialog( mainApp, { name: 'Onboarding Flow', @@ -24,10 +24,10 @@ export let onboardRig = (function (globals) { let fde = formDataEntries(event) if (fde?.intent === 'generate') { - appDialogs.phraseGenerate.render() + await appDialogs.phraseGenerate.render() appDialogs.phraseGenerate.showModal() } else if (fde?.intent === 'import') { - appDialogs.phraseImport.render() + await appDialogs.phraseImport.render() appDialogs.phraseImport.showModal() } }, diff --git a/src/rigs/pair-qr.js b/src/rigs/pair-qr.js index 8922c9d..c69d1e0 100644 --- a/src/rigs/pair-qr.js +++ b/src/rigs/pair-qr.js @@ -7,14 +7,14 @@ import { generateContactPairingURI, } from '../helpers/utils.js' -export let pairQrRig = (function (globals) { +export let pairQrRig = (async function (globals) { 'use strict'; let { mainApp, setupDialog, } = globals; - let pairQr = setupDialog( + let pairQr = await setupDialog( mainApp, { name: 'Pairing info', diff --git a/src/rigs/phrase-backup.js b/src/rigs/phrase-backup.js index 257c0e1..c63f912 100644 --- a/src/rigs/phrase-backup.js +++ b/src/rigs/phrase-backup.js @@ -5,14 +5,14 @@ import { setClipboard, } from '../helpers/utils.js' -export let phraseBackupRig = (function (globals) { +export let phraseBackupRig = (async function (globals) { 'use strict'; let { mainApp, setupDialog, appDialogs, } = globals; - let phraseBackup = setupDialog( + let phraseBackup = await setupDialog( mainApp, { name: 'New Wallet', @@ -83,7 +83,7 @@ export let phraseBackupRig = (function (globals) { phraseBackup.close() if (runEncryption) { - appDialogs.walletEncrypt.render( + await appDialogs.walletEncrypt.render( { wallet, }, diff --git a/src/rigs/phrase-generate.js b/src/rigs/phrase-generate.js index 0354d9a..22f9b95 100644 --- a/src/rigs/phrase-generate.js +++ b/src/rigs/phrase-generate.js @@ -6,7 +6,7 @@ import { ALIAS_REGEX, } from '../helpers/constants.js' -export let phraseGenerateRig = (function (globals) { +export let phraseGenerateRig = (async function (globals) { 'use strict'; let { @@ -15,7 +15,7 @@ export let phraseGenerateRig = (function (globals) { deriveWalletData, generateWalletData, } = globals; - let phraseGenerate = setupDialog( + let phraseGenerate = await setupDialog( mainApp, { name: 'New Wallet', @@ -113,7 +113,7 @@ export let phraseGenerateRig = (function (globals) { // console.log('GENERATE wallet!', wallet) - appDialogs.phraseBackup.render( + await appDialogs.phraseBackup.render( { wallet, }, diff --git a/src/rigs/phrase-import.js b/src/rigs/phrase-import.js index 3839d73..116550e 100644 --- a/src/rigs/phrase-import.js +++ b/src/rigs/phrase-import.js @@ -8,7 +8,7 @@ import { PHRASE_REGEX, } from '../helpers/constants.js' -export let phraseImportRig = (function (globals) { +export let phraseImportRig = (async function (globals) { 'use strict'; let { @@ -38,7 +38,7 @@ export let phraseImportRig = (function (globals) { } } - let phraseImport = setupDialog( + let phraseImport = await setupDialog( mainApp, { name: 'Existing Wallet', @@ -175,90 +175,129 @@ export let phraseImportRig = (function (globals) { `, fields: html``, events: { + handleClose: ( + state, + resolve = res=>{}, + reject = res=>{}, + ) => async event => { + event.preventDefault() + state.removeAllListeners() + + if (state.elements.dialog.returnValue !== 'cancel') { + resolve(state.elements.dialog.returnValue) + } else { + state.keystoreFile = '' + state.keystoreData = null + state.render(state) + resolve('cancel') + } + console.log( + 'DIALOG handleClose', + state.modal.rendered[state.slugs.dialog], + ) + + setTimeout(t => { + state.modal.rendered[state.slugs.dialog] = null + event?.target?.remove() + console.log( + 'DIALOG handleClose setTimeout', + state.delay, + // modal.rendered[state.slugs.dialog], + state.modal.rendered, + ) + }, state.delay) + }, handleDragOver: state => async event => { event.preventDefault() event.stopPropagation() - // console.log( - // 'PHRASE IMPORT DRAG OVER', - // // state, - // event.target, - // // event?.dataTransfer?.items, - // // event.target.files, - // ) if ( event.target.classList.contains('updrop') ) { + console.log( + 'PHRASE IMPORT DRAG OVER', + // state, + event.target, + // event?.dataTransfer?.items, + // event.target.files, + ) + event.target.classList.add('drag-over') } }, handleDragLeave: state => async event => { event.preventDefault() event.stopPropagation() - // console.log( - // 'PHRASE IMPORT DRAG LEAVE', - // // state, - // event.target, - // // event?.dataTransfer?.items, - // // event.target.files, - // ) if ( event.target.classList.contains('updrop') ) { + console.log( + 'PHRASE IMPORT DRAG LEAVE', + // state, + event.target, + // event?.dataTransfer?.items, + // event.target.files, + ) + event.target.classList.remove('drag-over') } }, handleDragEnd: state => async event => { event.preventDefault() event.stopPropagation() - // console.log( - // 'PHRASE IMPORT DRAG END', - // // state, - // event.target, - // // event?.dataTransfer?.items, - // // event.target.files, - // ) if ( event.target.classList.contains('updrop') ) { + console.log( + 'PHRASE IMPORT DRAG END', + // state, + event.target, + // event?.dataTransfer?.items, + // event.target.files, + ) + event.target.classList.add('dropped') } }, handleDrop: state => async event => { event.preventDefault() event.stopPropagation() - // console.log( - // 'PHRASE IMPORT DROP', - // state, event.target, - // event?.dataTransfer?.items, - // event.target.files - // ) - - - if (event.dataTransfer.items) { - [...event.dataTransfer.items].forEach((item, i) => { - if (item.kind === "file") { - const file = item.getAsFile(); - // console.log(`ITEMS file[${i}].name = ${file.name}`, file); + + if ( + event.target.classList.contains('updrop') + ) { + console.log( + 'PHRASE IMPORT DROP', + state, event.target, + event?.dataTransfer?.items, + event.target.files + ) + + if (event.dataTransfer.items) { + [...event.dataTransfer.items].forEach((item, i) => { + if (item.kind === "file") { + const file = item.getAsFile(); + // console.log(`ITEMS file[${i}].name = ${file.name}`, file); + readFile( + file, + processFile(state, event), + ) + state.keystoreFile = file.name + state.render(state) + } + }); + } else { + [...event.dataTransfer.files].forEach((file, i) => { readFile( file, processFile(state, event), ) state.keystoreFile = file.name state.render(state) - } - }); - } else { - [...event.dataTransfer.files].forEach((file, i) => { - readFile( - file, - processFile(state, event), - ) - state.keystoreFile = file.name - state.render(state) - }); + }); + } } }, handleChange: state => async event => { @@ -281,7 +320,7 @@ export let phraseImportRig = (function (globals) { let fde = formDataEntries(event) if (state.walletImportData) { - appDialogs.walletDecrypt.render({ + await appDialogs.walletDecrypt.render({ walletImportData: state.walletImportData }) await appDialogs.walletDecrypt.showModal() @@ -312,7 +351,7 @@ export let phraseImportRig = (function (globals) { localStorage.selectedAlias = appState.selectedAlias if (state.keystoreData) { - appDialogs.walletDecrypt.render({ + await appDialogs.walletDecrypt.render({ keystore: state.keystoreData }) await appDialogs.walletDecrypt.showModal() @@ -344,7 +383,7 @@ export let phraseImportRig = (function (globals) { phraseImport.close() - appDialogs.walletEncrypt.render( + await appDialogs.walletEncrypt.render( { wallet, }, diff --git a/src/rigs/request-qr.js b/src/rigs/request-qr.js index 9066c3b..1f8b64c 100644 --- a/src/rigs/request-qr.js +++ b/src/rigs/request-qr.js @@ -8,14 +8,14 @@ import { roundUsing, } from '../helpers/utils.js' -export let requestQrRig = (function (globals) { +export let requestQrRig = (async function (globals) { 'use strict'; let { mainApp, setupDialog, } = globals; - let requestQr = setupDialog( + let requestQr = await setupDialog( mainApp, { name: 'Share to receive funds', diff --git a/src/rigs/scan.js b/src/rigs/scan.js index 754ff39..0c481e1 100644 --- a/src/rigs/scan.js +++ b/src/rigs/scan.js @@ -3,14 +3,14 @@ import { lit as html } from '../helpers/lit.js' // formDataEntries, // } from '../helpers/utils.js' -export let scanContactRig = (function (globals) { +export let scanContactRig = (async function (globals) { 'use strict'; let { setupDialog, mainApp, } = globals; - let scanContact = setupDialog( + let scanContact = await setupDialog( mainApp, { name: 'Scan a Contact', @@ -100,7 +100,7 @@ export let scanContactRig = (function (globals) { } setTimeout(t => { - state.rendered = null + state.modal.rendered[state.slugs.dialog] = null event?.target?.remove() }, state.delay) }, diff --git a/src/rigs/send-confirm.js b/src/rigs/send-confirm.js index fac8d56..edbc608 100644 --- a/src/rigs/send-confirm.js +++ b/src/rigs/send-confirm.js @@ -5,7 +5,7 @@ import { sortContactsByAlias, } from '../helpers/utils.js' -export let sendConfirmRig = (function (globals) { +export let sendConfirmRig = (async function (globals) { 'use strict'; let { @@ -13,7 +13,7 @@ export let sendConfirmRig = (function (globals) { sendTx, store, userInfo, contactsList, } = globals - let sendConfirm = setupDialog( + let sendConfirm = await setupDialog( mainApp, { name: 'Confirm Send', @@ -194,7 +194,7 @@ export let sendConfirmRig = (function (globals) { } sendConfirm.close(fde.intent) - appDialogs.sendOrRequest.close(fde.intent) + appDialogs.sendOrReceive.close(fde.intent) }, }, } diff --git a/src/rigs/send-or-request.js b/src/rigs/send-or-request.js index 99fa280..3b0854d 100644 --- a/src/rigs/send-or-request.js +++ b/src/rigs/send-or-request.js @@ -7,7 +7,7 @@ import { roundUsing, } from '../helpers/utils.js' -export let sendOrReceiveRig = (function (globals) { +export let sendOrReceiveRig = (async function (globals) { 'use strict'; let { @@ -16,7 +16,7 @@ export let sendOrReceiveRig = (function (globals) { wallet, wallets, accounts, walletFunds, } = globals - let sendOrReceive = setupDialog( + let sendOrReceive = await setupDialog( mainApp, { name: 'Send or Receive', @@ -297,7 +297,7 @@ export let sendOrReceiveRig = (function (globals) { // ) if (fde?.intent === 'scan_qr_code') { - appDialogs.scanContact.render( + await appDialogs.scanContact.render( { wallet: state.wallet, }, @@ -402,7 +402,7 @@ export let sendOrReceiveRig = (function (globals) { walletFunds.balance - Number(fde.amount) ))) - appDialogs.requestQr.render( + await appDialogs.requestQr.render( { name: 'Insufficient wallet funds', wallet: receiveWallet, @@ -449,7 +449,7 @@ export let sendOrReceiveRig = (function (globals) { ) } - appDialogs.sendConfirm.render( + await appDialogs.sendConfirm.render( { wallet: state.wallet, // wallet: sendWallet, @@ -543,7 +543,7 @@ export let sendOrReceiveRig = (function (globals) { } ) - appDialogs.requestQr.render( + await appDialogs.requestQr.render( { name: 'Share to receive funds', footer: state => html`