Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix batch & receive dialog address generation #60

Merged
merged 15 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ See the [Stage 2](/../../milestone/2) milestone
- [ ] Contact/Payment Share Features
- [ ] SMS (sms:)
- [ ] Email (mailto:)
- [ ] Transactions view
- [ ] Table with filter/sort
- [ ] Select & Copy as CSV
- [ ] View & manage addresses associated with Wallet
- [ ] Coin Control
- [ ] Set Fund Denomination for Send & Request payments
Expand Down
32 changes: 27 additions & 5 deletions src/components/contacts-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ const initialState = {
<div>
${
state.contacts.length > 0
? (await Promise.all(state.contacts.map(async c => await state.item(c)))).join('')
? (
await Promise.all(
state.contacts.map(async c => await state.item(c))
)
).join('')
: ''
}
${
Expand Down Expand Up @@ -118,7 +122,7 @@ const initialState = {
`
},
footer: async state => html`
<datalist id="contactAliases">
<datalist id="contactSendAliases">
${
state.contacts.length > 0
? (
Expand All @@ -134,9 +138,27 @@ const initialState = {
contact.info?.name || contact.alias
}</option>`
})
// .map(
// async c => await state.item(c)
// )
)
).join('')
: ''
}
</datalist>
<datalist id="contactReceiveAliases">
${
state.contacts.length > 0
? (
await Promise.all(
state.contacts
.filter(
c => c.alias &&
Object.keys(c.incoming || {}).length > 0
).map(contact => {
return html`<option value="@${
contact.alias
}">${
contact.info?.name || contact.alias
}</option>`
})
)
).join('')
: ''
Expand Down
2 changes: 1 addition & 1 deletion src/components/main-footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const initialState = {
rendered: null,
content: state => html`
<footer>
<h4>Alpha stage, not production ready. <span>Use at your own risk.</span></h4>
<h4>Alpha stage, not production ready. <div>Use at your own risk.</div></h4>
<h5>Checkout the <a target="_blank" href="https://github.com/dashhive/wallet-ui">Source Code</a></h5>
</footer>
`,
Expand Down
8 changes: 8 additions & 0 deletions src/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,11 @@ export const DASH_URI_REGEX = new RegExp(
/^(?:web\+)?(?<protocol>dash)(?:[:])(?:\/\/)?(?<address>X[a-zA-Z0-9]{33})?(?:(?:[?])(?<params>.+))?/,
'ig'
)

export const RECEIVE = 0 // DashHd.RECEIVE
export const CHANGE = 1 // DashHd.CHANGE

export const USAGE = {
RECEIVE,
CHANGE,
}
63 changes: 63 additions & 0 deletions src/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,52 @@ export function envoy(obj, ...initListeners) {
})
}

/**
* Creates a reactive signal
*
* Inspired By
* {@link https://gist.github.com/developit/a0430c500f5559b715c2dddf9c40948d Valoo} &
* {@link https://dev.to/ratiu5/implementing-signals-from-scratch-3e4c Signals from Scratch}
*
* @example
* let count = createSignal(0)
* console.log(count.value) // 0
* count.value = 2
* console.log(count.value) // 2
*
* let off = count.on((value) => {
* document.querySelector("body").innerHTML = value;
* });
*
* off(); // unsubscribe
*
* @param {Object} initialValue inital value
*/
export function createSignal(initialValue) {
let _value = initialValue;
let _last = _value;
const subs = [];

function pub() {
for (let s of subs) {
s && s(_value, _last);
}
}

return {
get value() { return _value; },
set value(v) {
_last = _value
_value = v;
pub();
},
on: s => {
const i = subs.push(s)-1;
return () => { subs[i] = 0; };
}
}
}

export async function restate(
state = {},
renderState = {},
Expand Down Expand Up @@ -999,3 +1045,20 @@ export async function getUniqueAlias(aliases, preferredAlias) {

return uniqueAlias
}

export function getPartialHDPath(wallet) {
return [
wallet.accountIndex,
wallet.usageIndex,
wallet.addressIndex,
].join('/')
}

export function getAddressIndexFromUsage(wallet, account, usage) {
let usageIndex = usage ?? wallet.usageIndex
return {
...account,
usageIndex,
addressIndex: account.usage[usageIndex],
}
}
Loading
Loading