@@ -2,11 +2,9 @@ import { lit as html } from '../helpers/lit.js'
2
2
import {
3
3
envoy ,
4
4
restate ,
5
- // sortContactsByAlias,
6
- // filterPairedContacts,
7
- // filterUnpairedContacts,
8
- // timeago,
9
- // getAvatar,
5
+ sortTransactionsByTime ,
6
+ timeago ,
7
+ getAvatar ,
10
8
} from '../helpers/utils.js'
11
9
12
10
let _handlers = [ ]
@@ -36,16 +34,20 @@ const initialState = {
36
34
return html `< span class ="flex flex-fill center "> No Transactions found</ span > `
37
35
}
38
36
37
+ let contact
38
+
39
39
return (
40
40
await Promise . all (
41
41
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
+ } ) ,
49
51
)
50
52
) . join ( '' )
51
53
} ,
@@ -56,84 +58,66 @@ const initialState = {
56
58
${ await state . list ( state ) }
57
59
</ div >
58
60
` ,
59
- item : async c => {
60
- // if ('string' === typeof c ) {
61
+ item : async ( tx , cnt ) => {
62
+ if ( 'string' === typeof tx ) {
61
63
return html `
62
64
< article >
63
65
< address >
64
- < h4 > <!-- Encrypted --> Transaction</ h4 >
66
+ < h4 > Transaction</ h4 >
65
67
</ address >
66
68
</ article >
67
69
`
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
+ `
137
121
} ,
138
122
footer : async state => html `` ,
139
123
slugs : {
0 commit comments