${
- state.contacts.length > 0 ?
- state.contacts.map(c => state.item(c)).join('') : ''
+ state.contacts.length > 0
+ ? state.contacts.map(c => state.item(c)).join('')
+ : ''
}
${
state.contacts.length === 0 ?
diff --git a/src/main.js b/src/main.js
index f6665b1..d0091af 100644
--- a/src/main.js
+++ b/src/main.js
@@ -30,6 +30,11 @@ import addContactRig from './rigs/add-contact.js'
import shareProfileRig from './rigs/profile.js'
import scanContactRig from './rigs/scan.js'
+// Example Dash URI's
+
+// let testDashReqUri = `dash:XYZdashAddressZYX?amount=0.50000000&label=test&message=give me monies`
+// let testDashExtUri = `web+dash://?xpub=xpub6FKUF6P1ULrfvSrhA9DKSS3MA3digsd27MSTMjBxCczsfYz7vcFLnbQwjP9CsAfEJsnD4UwtbU43iZaibv4vnzQNZmQAVcufN4r3pva8kTz&sub=01H5KG2NGES5RVMA85YB3M6G0G&nickname=Prime%208&profile=https://imgur.com/gallery/y6sSvCr.json&picture=https://i.imgur.com/y6sSvCr.jpeg&scope=sub,nickname,profile,xpub&redirect_uri=https://`
+
// form validation
const phraseRegex = new RegExp(
/^([a-zA-Z]+\s){11,}([a-zA-Z]+)$/
@@ -47,6 +52,7 @@ let appState = envoy(
encryptionPassword: null,
selected_wallet: '',
selected_alias: '',
+ contacts: [],
},
(state, oldState) => {
if (state.foo !== oldState.bar) {
@@ -78,7 +84,7 @@ let contactsList = await setupContactsList(
mainApp,
{
events: {
- handleClick: state => event => {
+ handleClick: state => async event => {
event.preventDefault()
// console.warn(
// 'handle contacts click',
@@ -89,9 +95,71 @@ let contactsList = await setupContactsList(
event.target?.id === 'add_contact' ||
event.target?.parentNode?.id === 'add_contact'
) {
+ let selectedWallet = wallets?.[appState.selected_wallet]
+ let accountIndex = selectedWallet
+ ?.accountIndex || 0
+
+ let shareAccount
+ let newContact
+
+ if (appState.phrase) {
+ console.log(
+ 'share qr current wallet',
+ accountIndex,
+ selectedWallet?.xkeyId,
+ selectedWallet,
+ )
+
+ accountIndex += 1
+
+ let upWallet = await store.wallets.setItem(
+ appState.selected_wallet,
+ {
+ ...selectedWallet,
+ accountIndex,
+ }
+ )
+ wallets[appState.selected_wallet] = upWallet
+
+ shareAccount = await deriveWalletData(
+ appState.phrase,
+ accountIndex
+ )
+
+ console.log(
+ 'share qr derived wallet',
+ accountIndex,
+ // shareAccount?.xkeyId,
+ shareAccount,
+ // wallet,
+ )
+
+ newContact = await store.contacts.setItem(
+ // shareAccount.id,
+ shareAccount.xkeyId,
+ {
+ request: {
+ accountIndex,
+ xprv: shareAccount.xprv,
+ xpub: shareAccount.xpub,
+ id: shareAccount.id,
+ xkeyId: shareAccount.xkeyId,
+ addressKeyId: shareAccount.addressKeyId,
+ address: shareAccount.address,
+ },
+ }
+ )
+
+ console.log(
+ 'share qr new contact',
+ newContact,
+ )
+ }
+
addContact.render(
{
- wallet,
+ wallet: shareAccount,
+ contact: newContact,
},
'afterend',
)
@@ -679,7 +747,7 @@ async function main() {
mainApp, setupDialog, appState,
wallet, wallets,
bodyNav, dashBalance, onboard,
- scanContact,
+ scanContact, store,
})
svgSprite.render()
@@ -882,9 +950,26 @@ async function main() {
},
})
mainFtr.render()
+ // await store.contacts.setItem()
+
+ store.contacts.iterate(function(
+ value, key, iterationNumber
+ ) {
+ appState.contacts.push(value)
+ console.log('store.contacts.iterate', key, value, iterationNumber)
+ return appState.contacts
+ }).then(function(result) {
+ console.log(
+ 'Iteration has completed, last iterated pair:'
+ );
+ console.log(result);
+ contactsList.render(appState)
+ }).catch(function(err) {
+ // This code runs if there were any errors
+ console.log(err);
+ });
await contactsList.render({
- contacts: [
- ]
+ contacts: appState.contacts
})
sendRequestBtn.render()
@@ -916,9 +1001,6 @@ async function main() {
shareAccount?.xkeyId,
shareAccount,
)
-
- // appState.selected_alias = `${fde.alias}`
- // appState.selected_wallet = wallet.id
}
shareProfile.render(
diff --git a/src/rigs/add-contact.js b/src/rigs/add-contact.js
index 8c7af21..e728cde 100644
--- a/src/rigs/add-contact.js
+++ b/src/rigs/add-contact.js
@@ -1,6 +1,8 @@
import { lit as html } from '../helpers/lit.js'
+import { qrSvg } from '../helpers/qr.js'
import {
formDataEntries,
+ setClipboard,
} from '../helpers/utils.js'
const aliasRegex = new RegExp(
@@ -13,7 +15,7 @@ export let addContactRig = (function (globals) {
let {
setupDialog, mainApp, wallet, wallets,
appState, bodyNav, dashBalance, onboard,
- scanContact,
+ scanContact, store,
} = globals;
let addContact = setupDialog(
@@ -28,10 +30,9 @@ export let addContactRig = (function (globals) {
scanAlt: 'Scan Contact QR Code',
cancelTxt: 'Cancel',
cancelAlt: `Cancel`,
- closeTxt: html`
`,
closeAlt: `Close`,
+ closeTxt: html`
`,
+ placement: 'wide',
footer: state => html`
`,
- content: state => html`
+ content: state => {
+ let shareParams = new URLSearchParams([
+ ["xpub", state.wallet?.xpub || ''],
+ ["sub", state.wallet?.xkeyId || ''],
+ [
+ 'preferred_username',
+ appState.selected_alias || ''
+ ],
+ ['scope', 'sub,preferred_username,xpub']
+ ]);
+ let shareURI = new URL(`web+dash://?${shareParams}`)
+
+ return html`
${state.header(state)}
-
${state.footer(state)}
- `,
+ `},
fields: html``,
events: {
+ handleChange: state => async event => {
+ event.preventDefault()
+ if (
+ event?.target?.validity?.patternMismatch &&
+ event?.target?.type !== 'checkbox'
+ ) {
+ let label = event.target?.previousElementSibling?.textContent?.trim()
+ if (label) {
+ event.target.setCustomValidity(`Invalid ${label}`)
+ }
+ } else {
+ event.target.setCustomValidity('')
+ }
+ event.target.reportValidity()
+
+ // console.log(
+ // '+contact handleChange',
+ // event,
+ // event.target?.name,
+ // event.target?.value
+ // )
+ if (event.target?.name === 'contactAlias') {
+ let newContact = await store.contacts.setItem(
+ // state.wallet.id,
+ state.wallet.xkeyId,
+ {
+ ...state.contact,
+ profile: {
+ ...(state.contact.profile || {}),
+ preferred_username: event.target?.value,
+ },
+ }
+ )
+ // console.log(
+ // '+contact handleChange newContact',
+ // newContact
+ // )
+ }
+ },
+ handleClick: state => async event => {
+ if (
+ event.target?.classList?.contains('copy') ||
+ event.target?.classList?.contains('icon-copy')
+ ) {
+ event.preventDefault()
+ event.stopPropagation()
+ setClipboard(event)
+ }
+ },
+ handleRender: state => {
+ console.log(
+ '+contact app state & wallets',
+ appState,
+ state,
+ )
+ },
handleSubmit: state => async event => {
event.preventDefault()
event.stopPropagation()
- // event.target.alias.setCustomValidity('')
- // event.target.alias.reportValidity()
+ // event.target.contactAlias.setCustomValidity('')
+ // event.target.contactAlias.reportValidity()
console.log('ADD CONTACT!', state, event)
@@ -141,28 +235,76 @@ export let addContactRig = (function (globals) {
)
let showScan = await scanContact.showModal()
+ let scannedUrl = new URL(showScan)
+
console.log(
'showScan',
showScan,
+ scannedUrl,
// scanContact,
// scanContact?.element?.returnValue
)
- let [, addr] = showScan?.split('dash://')
- if (addr) {
+ let { searchParams, pathname } = scannedUrl
+ let addr = pathname.replaceAll('//', '')
+ let {
+ xpub, name, preferred_username
+ } = Object.fromEntries(
+ searchParams?.entries()
+ )
+ let aOrX = addr || xpub
+
+ if (aOrX) {
+ // event.target.addr.value = addr
+ event.target.contactAddr.value = aOrX
+ }
+ if (name) {
+ // event.target.addr.value = addr
+ event.target.contactName.value = name
+ }
+ if (preferred_username) {
// event.target.addr.value = addr
- event.target.addr.value = showScan
+ event.target.contactAlias.value = preferred_username
}
+
return;
}
- if (!String(fde.alias)?.trim()) {
- event.target.alias.setCustomValidity(
+ if (!String(fde.contactAddr)?.trim()) {
+ event.target.contactAddr.setCustomValidity(
+ 'An address, Xprv/Xpub or URI is required'
+ )
+ event.target.reportValidity()
+ return;
+ }
+
+ if (!String(fde.contactAlias)?.trim()) {
+ event.target.contactAlias.setCustomValidity(
'An alias is required'
)
event.target.reportValidity()
return;
}
+ let storedContact = await store.contacts.getItem(
+ state.wallet.xkeyId,
+ )
+
+ let pairedContact = await store.contacts.setItem(
+ // state.wallet.id,
+ state.wallet.xkeyId,
+ {
+ ...storedContact,
+ profile: {
+ ...(storedContact.profile || {}),
+ name: event.target.contactName.value,
+ preferred_username: event.target.contactAlias.value,
+ },
+ uri: event.target.contactAddr.value,
+ }
+ )
+
+ console.log('pairedContact', pairedContact)
+
// let initialized
// wallet = state.wallet
diff --git a/src/rigs/profile.js b/src/rigs/profile.js
index 7df4a5c..63fd30e 100644
--- a/src/rigs/profile.js
+++ b/src/rigs/profile.js
@@ -12,27 +12,6 @@ export let shareProfileRig = (function (globals) {
setupDialog, mainApp, wallet, wallets,
appState, bodyNav, dashBalance, onboard,
} = globals;
- // store.addresses.key(1).then(function(keyName) {
- // // Name of the key.
- // console.log('first key', keyName);
- // let dashSvg = qrSvg(
- // `dash://${keyName}`,
- // {
- // background: '#fff0',
- // color: 'currentColor',
- // indent: 1,
- // padding: 1,
- // size: 'mini',
- // container: 'svg-viewbox',
- // join: true,
- // }
- // )
- // // console.log('first key qr code', dashSvg);
- // mainApp.insertAdjacentHTML('beforeend', dashSvg)
- // }).catch(function(err) {
- // // This code runs if there were any errors
- // console.error('failed to load first key', err);
- // });
let shareProfile = setupDialog(
mainApp,
@@ -46,6 +25,7 @@ export let shareProfileRig = (function (globals) {
submitAlt: 'QR Code',
cancelTxt: 'Cancel',
cancelAlt: `Cancel`,
+ placement: 'wide',
closeTxt: html`
`,
@@ -66,7 +46,7 @@ export let shareProfileRig = (function (globals) {
content: state => html`
${state.header(state)}
-
+