Skip to content

Commit

Permalink
feat(ui): ✨ add send confirmation dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
jojobyte committed Oct 27, 2023
1 parent fbd60b6 commit 79fbbef
Show file tree
Hide file tree
Showing 9 changed files with 304 additions and 81 deletions.
10 changes: 1 addition & 9 deletions src/helpers/qr.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import { toDash } from './utils.js'

let qrWidth = 2 + 33 + 2;

/**
* @typedef QrOpts
* @property {String} [background]
Expand Down Expand Up @@ -57,11 +55,5 @@ export function showQr(addr, duffs = 0) {
dashUri += `?amount=${dashAmount}`;
}

let dashQr = qrSvg(dashUri, { indent: 4, size: "mini" });
// let addrPad = Math.max(0, Math.ceil((qrWidth - dashUri.length) / 2));

// console.info(dashQr);
// console.info();
// console.info(" ".repeat(addrPad) + dashUri);
return dashQr
return qrSvg(dashUri, { indent: 4, size: "mini" });
}
1 change: 1 addition & 0 deletions src/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export async function deriveWalletData(
accountIndex,
addressIndex,
addressKeyId,
addressKey,
address,
xkeyId,
xkey,
Expand Down
16 changes: 16 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import addContactRig from './rigs/add-contact.js'
import editProfileRig from './rigs/edit-profile.js'
import scanContactRig from './rigs/scan.js'
import sendOrRequestRig from './rigs/send-or-request.js'
import sendConfirmRig from './rigs/send-confirm.js'

// Example Dash URI's

Expand Down Expand Up @@ -80,6 +81,7 @@ let appDialogs = envoy(
editProfile: {},
scanContact: {},
sendOrRequest: {},
sendConfirm: {},
},
)

Expand Down Expand Up @@ -141,9 +143,18 @@ let contactsList = await setupContactsList(
accountIndex
)

let addressIndex = 0
let { addresses, finalAddressIndex } = await batchAddressGenerate(
shareAccount,
accountIndex,
addressIndex,
)

console.log(
'share qr derived wallet',
accountIndex,
finalAddressIndex,
addresses,
// shareAccount?.xkeyId,
shareAccount,
// wallet,
Expand Down Expand Up @@ -307,6 +318,11 @@ async function main() {
wallet, deriveWalletData,
})

appDialogs.sendConfirm = sendConfirmRig({
mainApp, setupDialog, appDialogs,
wallet, deriveWalletData,
})

svgSprite.render()

document.addEventListener('submit', async event => {
Expand Down
169 changes: 169 additions & 0 deletions src/rigs/send-confirm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import { lit as html } from '../helpers/lit.js'
import {
formDataEntries,
} from '../helpers/utils.js'

export let sendConfirmRig = (function (globals) {
'use strict';

let {
mainApp, setupDialog, appDialogs,
wallet, deriveWalletData,
} = globals

let sendConfirm = setupDialog(
mainApp,
{
name: 'Confirm Send',
sendTxt: 'Send',
sendAlt: 'Send Dash',
cancelTxt: 'Cancel',
cancelAlt: `Cancel Send`,
closeTxt: html`<svg class="x" width="26" height="26" viewBox="0 0 26 26">
<use xlink:href="#icon-x"></use>
</svg>`,
closeAlt: `Cancel & Close`,
footer: state => html`
<footer class="inline row">
<button
class="rounded outline"
type="reset"
name="intent"
value="cancel"
title="${state.cancelAlt}"
>
<span>${state.cancelTxt}</span>
</button>
<button
class="rounded"
type="submit"
name="intent"
value="send"
title="${state.sendAlt}"
>
<svg width="24" height="24" viewBox="0 0 24 24">
<use xlink:href="#icon-arrow-circle-up"></use>
</svg>
<span>${state.sendTxt}</span>
</button>
</footer>
`,
getContact: state => {
let to = state.contact?.info?.name
if (!to && state.contact?.alias) {
to = `@${state.contact?.alias}`
}
if (!to) {
to = state.to
}
return to
},
content: state => html`
${state.header(state)}
<article>
<figure>
<figcaption>To</figcaption>
<div>${state.getContact(state)}</div>
</figure>
</article>
<article>
<figure>
<figcaption>Amount</figcaption>
<div class="big">
<svg width="32" height="33" viewBox="0 0 32 33">
<use xlink:href="#icon-dash-mark"></use>
</svg>
${state.amount}
</div>
</figure>
</article>
${state.footer(state)}
`,
events: {
handleClose: (
state,
resolve = res=>{},
reject = res=>{},
) => async event => {
event.preventDefault()
// event.stopPropagation()
state.removeAllListeners()

if (state.elements.dialog.returnValue !== 'cancel') {
resolve(state.elements.dialog.returnValue)
} else {
resolve('cancel')
}
},
handleSubmit: state => async event => {
event.preventDefault()
event.stopPropagation()
// event.target.to.setCustomValidity(
// ''
// )
// event.target.to.reportValidity()

let fde = formDataEntries(event)

// if (fde.intent === 'send' && !fde.to) {
// event.target.to.setCustomValidity(
// 'You must specify a contact or address to send to'
// )
// event.target.to.reportValidity()
// return;
// }

let outWallet, address, sendWallet = {}

if (state.contact) {
outWallet = Object.values(state.contact?.outgoing)?.[0]
}

if (fde.intent === 'send') {
if (outWallet) {
sendWallet = await deriveWalletData(
outWallet?.xpub,
0,
outWallet?.addressIndex + 1,
)
address = sendWallet.address
} else {
address = state.to
}

console.log(
`${fde.intent} TO ${address}`,
${state.amount || 0}`,
state.contact,
// {
// xkeyId: outWallet?.xkeyId,
// addressKeyId: outWallet?.addressKeyId,
// addressIndex: outWallet?.addressIndex,
// address: outWallet?.address,
// },
{
xkeyId: sendWallet?.xkeyId,
addressKeyId: sendWallet?.addressKeyId,
addressIndex: sendWallet?.addressIndex,
address,
},
)
}

sendConfirm.close(fde.intent)
appDialogs.sendOrRequest.close(fde.intent)
},
},
}
)

// @ts-ignore
globals.sendConfirm = sendConfirm;

return sendConfirm
})

export default sendConfirmRig
Loading

0 comments on commit 79fbbef

Please sign in to comment.