Skip to content

Commit

Permalink
feat(ui): ✨ Hook up functionality to Add a New Contact form
Browse files Browse the repository at this point in the history
  • Loading branch information
jojobyte committed Oct 22, 2023
1 parent 8e83ec7 commit f8b65f5
Show file tree
Hide file tree
Showing 6 changed files with 362 additions and 128 deletions.
7 changes: 4 additions & 3 deletions src/components/contacts-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const initialState = {
<h6>Contacts (${state.contacts.length})</h6>
<button
id="add_contact"
class="pill rounded copy"
class="pill rounded"
title="Add a Contact"
>
<svg class="plus-circle" width="26" height="26" viewBox="0 0 16 16">
Expand All @@ -55,8 +55,9 @@ const initialState = {
<div>
${
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 ?
Expand Down
98 changes: 90 additions & 8 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]+)$/
Expand All @@ -47,6 +52,7 @@ let appState = envoy(
encryptionPassword: null,
selected_wallet: '',
selected_alias: '',
contacts: [],
},
(state, oldState) => {
if (state.foo !== oldState.bar) {
Expand Down Expand Up @@ -78,7 +84,7 @@ let contactsList = await setupContactsList(
mainApp,
{
events: {
handleClick: state => event => {
handleClick: state => async event => {
event.preventDefault()
// console.warn(
// 'handle contacts click',
Expand All @@ -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',
)
Expand Down Expand Up @@ -679,7 +747,7 @@ async function main() {
mainApp, setupDialog, appState,
wallet, wallets,
bodyNav, dashBalance, onboard,
scanContact,
scanContact, store,
})

svgSprite.render()
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -916,9 +1001,6 @@ async function main() {
shareAccount?.xkeyId,
shareAccount,
)

// appState.selected_alias = `${fde.alias}`
// appState.selected_wallet = wallet.id
}

shareProfile.render(
Expand Down
Loading

0 comments on commit f8b65f5

Please sign in to comment.