Skip to content

Commit 348a6e8

Browse files
committed
feat(ui): ✨ display transactions with contact
1 parent 4ed124b commit 348a6e8

File tree

9 files changed

+472
-246
lines changed

9 files changed

+472
-246
lines changed

src/components/transactions-list.js

Lines changed: 68 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import { lit as html } from '../helpers/lit.js'
22
import {
33
envoy,
44
restate,
5-
// sortContactsByAlias,
6-
// filterPairedContacts,
7-
// filterUnpairedContacts,
8-
// timeago,
9-
// getAvatar,
5+
sortTransactionsByTime,
6+
timeago,
7+
getAvatar,
108
} from '../helpers/utils.js'
119

1210
let _handlers = []
@@ -36,16 +34,20 @@ const initialState = {
3634
return html`<span class="flex flex-fill center">No Transactions found</span>`
3735
}
3836

37+
let contact
38+
3939
return (
4040
await Promise.all(
4141
state.transactions
42-
// .filter(
43-
// state.showUnpaired
44-
// ? filterUnpairedContacts
45-
// : filterPairedContacts
46-
// )
47-
// .sort(sortContactsByAlias)
48-
.map(async c => await state.item(c)),
42+
.sort(sortTransactionsByTime)
43+
.map(async tx => {
44+
if (state.contacts?.length > 0) {
45+
contact = state.contacts.find(
46+
c => c.alias === tx.alias
47+
)
48+
}
49+
return await state.item(tx, contact)
50+
}),
4951
)
5052
).join('')
5153
},
@@ -56,84 +58,66 @@ const initialState = {
5658
${await state.list(state)}
5759
</div>
5860
`,
59-
item: async c => {
60-
// if ('string' === typeof c) {
61+
item: async (tx, cnt) => {
62+
if ('string' === typeof tx) {
6163
return html`
6264
<article>
6365
<address>
64-
<h4><!-- Encrypted --> Transaction</h4>
66+
<h4>Transaction</h4>
6567
</address>
6668
</article>
6769
`
68-
// }
69-
70-
// let outgoing = Object.values(c?.outgoing || {})
71-
// let paired = outgoing.length > 0
72-
// let out = outgoing?.[0]
73-
// let created = c.createdAt
74-
// ? timeago(Date.now() - (new Date(c.createdAt)).getTime())
75-
// : ''
76-
// let user = c.alias || c.info?.preferred_username
77-
// let finishPairing = !paired
78-
// ? 'Finish pairing with contact'
79-
// : ''
80-
// let enterContactInfo = !paired || !user
81-
// ? `Enter contact information for`
82-
// : ''
83-
// let name = c.info?.name
84-
85-
// if (
86-
// !name &&
87-
// !user &&
88-
// !out?.xkeyId &&
89-
// out?.address
90-
// ) {
91-
// name = out?.address
92-
// } else if (!name) {
93-
// name = created
94-
// }
95-
96-
// let inId = Object.keys(c?.incoming || {})?.[0]?.split('/')[1]
97-
98-
// let atUser = user
99-
// ? `@${user}`
100-
// : ''
101-
// let itemAlias = user
102-
// ? `${atUser}${ !paired ? ' - ' : '' }${finishPairing}`
103-
// : finishPairing || enterContactInfo
104-
// let itemName = name
105-
// ? `${name}`
106-
// : ''
107-
// let itemSub = inId
108-
// ? `href="/#!/contact/${atUser || inId}" data-id="${inId}"`
109-
// : ''
110-
// let itemCtrls = paired
111-
// ? html`<aside class="inline row">
112-
// <button class="pill rounded">
113-
// <svg width="24" height="24" viewBox="0 0 24 24">
114-
// <use xlink:href="#icon-arrow-circle-up"></use>
115-
// </svg>
116-
// </button>
117-
// <button class="pill rounded">
118-
// <svg width="24" height="24" viewBox="0 0 24 24">
119-
// <use xlink:href="#icon-arrow-circle-down"></use>
120-
// </svg>
121-
// </button>
122-
// </aside>`
123-
// : ''
124-
125-
// itemCtrls = '' // temp override
126-
127-
// return html`
128-
// <a ${itemSub}>
129-
// ${await getAvatar(c)}
130-
// <address>
131-
// <h4>${itemAlias}</h4>
132-
// <h5>${itemName}</h5>
133-
// </address>
134-
// ${itemCtrls}
135-
// </a>
136-
// `
70+
}
71+
72+
let time
73+
let txDate = new Date(tx.time * 1000)
74+
let user = cnt?.alias || cnt?.info?.preferred_username || tx?.alias || ''
75+
let name = cnt?.info?.name
76+
let addr = tx?.vout?.[0]?.scriptPubKey?.addresses?.[0]
77+
78+
if (tx?.dir !== 'sent') {
79+
addr = tx?.vin?.[0]?.addr
80+
}
81+
if (tx.time) {
82+
time = timeago(Date.now() - txDate.getTime())
83+
}
84+
85+
if (
86+
!name && user
87+
) {
88+
name = `@${user}`
89+
} else if (
90+
!name && !user
91+
) {
92+
name = html`<span title="${addr}">${addr.substring(0,3)}...${addr.substring(addr.length - 3)}</span>`
93+
}
94+
95+
let itemAmount = tx.receivedAmount || tx.valueOut || 0
96+
97+
let itemCtrls = html`<aside class="inline row dang">
98+
-${itemAmount}
99+
</aside>`
100+
let itemTitle = `Sent on`
101+
let itemDir = `To <strong>${name}</strong>`
102+
103+
if (tx?.dir !== 'sent') {
104+
itemTitle = `Received on`
105+
itemDir = `From <strong>${name}</strong>`
106+
itemCtrls = html`<aside class="inline row succ">
107+
+${itemAmount}
108+
</aside>`
109+
}
110+
111+
return html`
112+
<a href="https://insight.dash.org/insight/tx/${tx?.txid}" target="_blank" rel="noreferrer" title="${itemTitle} ${txDate.toLocaleString()}">
113+
${await getAvatar(cnt)}
114+
<address>
115+
<h4>${itemDir}</h4>
116+
<h5>${time}</h5>
117+
</address>
118+
${itemCtrls}
119+
</a>
120+
`
137121
},
138122
footer: async state => html``,
139123
slugs: {

src/helpers/utils.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,19 @@ export function sortContactsByName(a, b) {
523523
return 0;
524524
}
525525

526+
export function sortTransactionsByTime(a, b) {
527+
const timeA = a.time;
528+
const timeB = b.time;
529+
530+
if (timeA > timeB) {
531+
return -1;
532+
}
533+
if (timeA < timeB) {
534+
return 1;
535+
}
536+
return 0;
537+
}
538+
526539
export function DashURLSearchParams(params) {
527540
let searchParams
528541
let qry = {}

0 commit comments

Comments
 (0)