Skip to content

Commit 798cd61

Browse files
committed
refactor: ♻️ shift contact creation into model
The internal state of several components was not correctly updating/resetting when some dialogs would close. this is a massive refactor to fix some of those underlying issues as well as move contact creation/updating out of the dialog so that we can programatically create a contact without user interaction, specifically useful for creating a crowdnode or maya contact.
1 parent b4b5acd commit 798cd61

24 files changed

+1297
-701
lines changed

src/components/contacts-list.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import {
1010
filterUnpairedContacts,
1111
} from '../utils/dash/local.js'
1212

13+
import {
14+
appState,
15+
} from '../state/index.js'
16+
1317
let _handlers = []
1418

1519
const initialState = {
@@ -21,7 +25,9 @@ const initialState = {
2125
showUnpaired: false,
2226
delay: 500,
2327
wallet: {},
24-
contacts: [],
28+
contacts: [
29+
...appState.contacts,
30+
],
2531
restate,
2632
render(
2733
renderState = {},

src/components/crowdnode-card.js

Lines changed: 84 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export const CrowdNodeCard = (() => {
2929
depositAlt: `Deposit to Crowdnode`,
3030
#Txt: '#',
3131
#Alt: `# for Crowdnode`,
32+
fundTxt: 'Fund Wallet',
33+
fundAlt: `Fund Wallet for Crowdnode`,
3234
placement: 'center',
3335
rendered: null,
3436
responsive: true,
@@ -42,7 +44,7 @@ export const CrowdNodeCard = (() => {
4244
...config,
4345
}
4446

45-
this.appElement = document.body
47+
// this.appElement = document.body
4648

4749
this.api = createSignal({})
4850

@@ -60,57 +62,76 @@ export const CrowdNodeCard = (() => {
6062
...config.elements,
6163
}
6264

65+
this.stage = []
66+
67+
Object.defineProperties(this, {
68+
stage: {
69+
get: () => [
70+
!this.api.value?.acceptedToS, // Stage 0
71+
this.api.value?.acceptedToS, // Stage 1
72+
this.api.value?.balance <= 0, // Stage 2
73+
this.api.value?.balance > 0, // Stage 3
74+
],
75+
},
76+
});
77+
6378
this.markup = {}
64-
this.markup.content = () => html`
65-
<header>
66-
<a href="https://app.crowdnode.io/" target="_blank" rel="noreferrer">
67-
<svg class="crowdnode-logo lock" width="26" height="26" viewBox="0 0 240 240">
68-
<use xlink:href="#icon-crowdnode-logo"></use>
69-
</svg>
70-
<span>CrowdNode</span>
71-
</a>
72-
</header>
79+
// # & Accept
80+
this.markup.stageOne = () => this.stage[0] && !this.stage[1] && html`
81+
<section class="flex col jc-between">
82+
Start earning interest by staking your Dash at CrowdNode
83+
</section>
7384
85+
<footer class="flex">
86+
<button
87+
class="rounded outline flex-fill"
88+
type="submit"
89+
name="intent"
90+
value="#"
91+
title="${this.state.#Alt}"
92+
>
93+
${this.state.#Txt}
94+
</button>
95+
</footer>
96+
`
97+
this.markup.stageTwo = () => this.stage[1] && this.stage[2] && html`
7498
<section class="flex col jc-between">
75-
${!this.api.value?.acceptedToS && html`
76-
Start earning interest by staking your Dash at CrowdNode
77-
`}
78-
${this.api.value?.acceptedToS && html`
79-
<p class="my-0"><em>
80-
Balance: Ð ${this.api.value?.balance}
81-
</em></p>
82-
`}
83-
${this.api.value?.acceptedToS && html`
84-
<p class="my-0"><em>
85-
Earned: Ð ${this.api.value?.earned}
86-
</em></p>
87-
`}
99+
Finish funding your account to start earning interest
88100
</section>
89101
90102
<footer class="flex">
91-
${!this.api.value?.acceptedToS && html`
92-
<button
93-
class="rounded outline flex-fill"
94-
type="submit"
95-
name="intent"
96-
value="#"
97-
title="${this.state.#Alt}"
98-
>
99-
${this.state.#Txt}
100-
</button>
101-
`}
102-
${this.api.value?.acceptedToS && html`
103-
<button
104-
class="rounded outline flex-fill"
105-
type="submit"
106-
name="intent"
107-
value="deposit"
108-
title="${this.state.depositAlt}"
109-
>
110-
${this.state.depositTxt}
111-
</button>
112-
`}
113-
${this.api.value?.acceptedToS && this.api.value?.balance > 0 && html`
103+
<button
104+
class="rounded outline flex-fill"
105+
type="submit"
106+
name="intent"
107+
value="fund"
108+
title="${this.state.fundAlt}"
109+
>
110+
${this.state.fundTxt}
111+
</button>
112+
</footer>
113+
`
114+
this.markup.stageThree = () => this.stage[1] && this.stage[3] && html`
115+
<section class="flex col jc-between">
116+
<p class="my-0"><em>
117+
Balance: Ð ${this.api.value?.balance}
118+
</em></p>
119+
<p class="my-0"><em>
120+
Earned: Ð ${this.api.value?.earned}
121+
</em></p>
122+
</section>
123+
124+
<footer class="flex">
125+
<button
126+
class="rounded outline flex-fill"
127+
type="submit"
128+
name="intent"
129+
value="deposit"
130+
title="${this.state.depositAlt}"
131+
>
132+
${this.state.depositTxt}
133+
</button>
134+
${this.stage[3] && html`
114135
<button
115136
class="rounded outline flex-fill"
116137
type="submit"
@@ -123,6 +144,20 @@ export const CrowdNodeCard = (() => {
123144
`}
124145
</footer>
125146
`
147+
this.markup.content = () => html`
148+
<header>
149+
<a href="https://app.crowdnode.io/" target="_blank" rel="noreferrer">
150+
<svg class="crowdnode-logo lock" width="26" height="26" viewBox="0 0 240 240">
151+
<use xlink:href="#icon-crowdnode-logo"></use>
152+
</svg>
153+
<span>CrowdNode</span>
154+
</a>
155+
</header>
156+
157+
${this.markup.stageOne()}
158+
${this.markup.stageTwo()}
159+
${this.markup.stageThree()}
160+
`
126161
this.markup = {
127162
...this.markup,
128163
...config.markup,
@@ -202,14 +237,16 @@ export const CrowdNodeCard = (() => {
202237
this.elements.form.name = this.slugs.form
203238
this.elements.form.innerHTML = this.markup.content()
204239

240+
console.log('CN Card render', this.stage, this.elements.form.innerHTML)
241+
205242
this.elements.form.addEventListener(
206243
'submit',
207244
this.events.submit,
208245
)
209246

210247
console.log('CARD RENDER', this, cfg)
211248

212-
if (!this.state.rendered) {
249+
if (!this.state.rendered && el) {
213250
el.insertAdjacentElement(position, this.elements.form)
214251
this.state.rendered = this.elements.form
215252
}

src/components/transactions-list.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const initialState = {
9898

9999
let itemAmount = tx.receivedAmount || tx.valueOut || 0
100100

101-
let itemCtrls = html`<aside class="inline row dang">
101+
let itemCtrls = html`<aside class="inline row dang" title="-${itemAmount}">
102102
-${itemAmount}
103103
</aside>`
104104
let itemTitle = `Sent on`
@@ -107,7 +107,7 @@ const initialState = {
107107
if (!['sent', 'outgoing'].includes(tx?.dir)) {
108108
itemTitle = `Received on`
109109
itemDir = `From <strong>${name}</strong>`
110-
itemCtrls = html`<aside class="inline row succ">
110+
itemCtrls = html`<aside class="inline row succ" title="+${itemAmount}">
111111
+${itemAmount}
112112
</aside>`
113113
}

0 commit comments

Comments
 (0)