FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sync2/src/pages/TransferNotifier.vue at master · javascriptit/sync2 · GitHub
javascriptit
sync2
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
sync2
/
src
/
pages
/
TransferNotifier.vue
Copy path
More file actions
More file actions
Latest commit
History
History
History
206 lines (198 loc) · 7.83 KB
Breadcrumbs
sync2
/
src
/
pages
/
TransferNotifier.vue
Copy path
File metadata and controls
206 lines (198 loc) · 7.83 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<
script
lang="ts">
import
Vue
from
'
vue
'
import
{
abis
}
from
'
src/consts
'
import
{
abi
}
from
'
thor-devkit
'
import
{
formatAmount
}
from
'
src/utils/format
'
export
default
Vue
.
extend
({
props: {
gid:
String
},
computed: {
thor()
:
Connex
.
Thor
{
return
this
.
$svc
.
bc
(
this
.
gid
).
thor
},
addresses()
:
string
[] {
if
(
!
this
.
wallets
) {
return
[]
}
return
Array
.
from
(
this
.
wallets
.
reduce
<
Set
<
string
>>((
prev
,
cur
)
=>
{
cur
.
meta
.
addresses
.
forEach
(
a
=>
prev
.
add
(
a
))
return
prev
},
new
Set
()))
},
//
compose vet transfer criteria
transferCriteria()
:
Connex
.
Thor
.
Filter
.
Criteria
<
'
transfer
'
>[] {
return
this
.
addresses
.
reduce
<
Connex
.
Thor
.
Filter
.
Criteria
<
'
transfer
'
>[]>((
prev
,
cur
)
=>
{
prev
.
push
({ sender:
cur
}, { recipient:
cur
})
return
prev
}, [])
},
//
compose token transfer criteria
eventCriteria()
:
Connex
.
Thor
.
Filter
.
Criteria
<
'
event
'
>[] {
const
tokens
=
this
.
tokens
if
(
!
tokens
) {
return
[]
}
return
this
.
addresses
.
reduce
<
Connex
.
Thor
.
Filter
.
Criteria
<
'
event
'
>[]>((
prev
,
cur
)
=>
{
tokens
.
forEach
(
spec
=>
{
const
ev
=
this
.
thor
.
account
(
spec
.
address
)
.
event
(
abis
.
transferEvent
)
prev
.
push
(
ev
.
asCriteria
({ _from:
cur
}),
ev
.
asCriteria
({ _to:
cur
}))
})
return
prev
}, [])
}
},
asyncComputed: {
wallets()
:
Promise
<
M
.
Wallet
[]
|
null
> {
return
this
.
$svc
.
wallet
.
getByGid
(
this
.
gid
)
},
async
tokens()
:
Promise
<
M
.
TokenSpec
[]
|
null
> {
const
[tokens, activeSymbols]
=
await
Promise
.
all
([
this
.
$svc
.
config
.
token
.
all
(),
this
.
$svc
.
config
.
token
.
activeSymbols
()
])
return
tokens
.
filter
(
token
=>
token
.
address
&&
//
exclude vet
token
.
gid
===
this
.
gid
&&
(
activeSymbols
.
includes
(
token
.
symbol
)
||
token
.
permanent
))
},
//
vet transfers
transfers: {
get()
:
Promise
<
Connex
.
Thor
.
Filter
.
Row
<
'
transfer
'
>[]
|
null
> {
return
this
.
guardRange
(
'
transfer
'
,
range
=>
{
const
criteria
=
this
.
transferCriteria
if
(
criteria
.
length
===
0
) {
return
Promise
.
resolve
([])
}
return
this
.
thor
.
filter
(
'
transfer
'
,
criteria
)
.
cache
(
this
.
addresses
)
.
range
(
range
)
.
apply
(
0
,
5
)
})
},
//
no auto update, but react to headNumber change
shouldUpdate() {
return
false
}
},
//
token transfers
events: {
get()
:
Promise
<
Connex
.
Thor
.
Filter
.
Row
<
'
event
'
>[]
|
null
> {
return
this
.
guardRange
(
'
event
'
,
range
=>
{
const
criteria
=
this
.
eventCriteria
if
(
criteria
.
length
===
0
) {
return
Promise
.
resolve
([])
}
return
this
.
thor
.
filter
(
'
event
'
,
criteria
)
.
cache
(
this
.
addresses
)
.
range
(
range
)
.
apply
(
0
,
5
)
})
},
//
no auto update, but react to headNumber change
shouldUpdate() {
return
false
}
}
},
watch: {
thor() {
this
.
$asyncComputed
.
events
.
update
()
this
.
$asyncComputed
.
transfers
.
update
()
},
transfers(
newVal
:
Connex
.
Thor
.
Filter
.
Row
<
'
transfer
'
>[]
|
null
) {
const
wallets
=
this
.
wallets
if
(
!
wallets
) {
return
}
newVal
&&
newVal
.
forEach
(
t
=>
{
let
w
=
wallets
.
find
(
w
=>
w
.
meta
.
addresses
.
includes
(
t
.
recipient
))
if
(
w
) {
this
.
notify
(
'
in
'
,
t
.
amount
,
18
,
'
VET
'
,
w
.
id
,
w
.
meta
.
addresses
.
indexOf
(
t
.
recipient
))
}
w
=
wallets
.
find
(
w
=>
w
.
meta
.
addresses
.
includes
(
t
.
sender
))
if
(
w
) {
this
.
notify
(
'
out
'
,
t
.
amount
,
18
,
'
VET
'
,
w
.
id
,
w
.
meta
.
addresses
.
indexOf
(
t
.
sender
))
}
})
},
events(
newVal
:
Connex
.
Thor
.
Filter
.
Row
<
'
event
'
>[]
|
null
) {
const
wallets
=
this
.
wallets
const
tokens
=
this
.
tokens
if
(
!
wallets
||
!
tokens
) {
return
}
newVal
&&
newVal
.
forEach
(
e
=>
{
const
token
=
tokens
.
find
(
t
=>
t
.
address
===
e
.
address
)
if
(
!
token
) {
return
}
const
{ _to, _from, _value }
:
Record
<
string
,
string
>
=
new
abi
.
Event
(
abis
.
transferEvent
).
decode
(
e
.
data
,
e
.
topics
)
let
w
=
wallets
.
find
(
w
=>
w
.
meta
.
addresses
.
includes
(
_to
))
if
(
w
) {
this
.
notify
(
'
in
'
,
_value
,
token
.
decimals
,
token
.
symbol
,
w
.
id
,
w
.
meta
.
addresses
.
indexOf
(
_to
))
}
w
=
wallets
.
find
(
w
=>
w
.
meta
.
addresses
.
includes
(
_from
))
if
(
w
) {
this
.
notify
(
'
out
'
,
_value
,
token
.
decimals
,
token
.
symbol
,
w
.
id
,
w
.
meta
.
addresses
.
indexOf
(
_from
))
}
})
}
},
methods: {
//
provides stored range for the query
async
guardRange<
T
extends
Connex
.
Thor
.
Filter
.
WithMeta
>(
kind
:
string
,
query
:
(
range
:
Connex
.
Thor
.
Filter
.
Range
)
=>
Promise
<
T
[]>)
:
Promise
<
T
[]> {
const
key
=
`
${
this
.
gid
}-notifier-filter-range-start_${
kind
}
`
const
headNum
=
this
.
thor
.
status
.
head
.
number
const
savedRange
=
localStorage
.
getItem
(
key
)
const
rangeStart
=
Math
.
max
(
parseInt
(
savedRange
!
)
||
headNum
,
headNum
-
8640
)
//
span no longer than a day
if
(
rangeStart
===
0
) {
return
[]
}
const
result
=
await
query
({ unit:
'
block
'
, from:
rangeStart
, to:
2
**
32
-
1
})
if
(
result
.
length
>
0
) {
localStorage
.
setItem
(
key
, (
result
[
result
.
length
-
1
].
meta
.
blockNumber
+
1
).
toString
())
}
else
if
(
!
savedRange
||
headNum
>
rangeStart
+
100
) {
localStorage
.
setItem
(
key
,
headNum
.
toString
())
}
return
result
},
notify(
dir
:
'
in
'
|
'
out
'
,
amount
:
string
,
decimals
:
number
,
symbol
:
string
,
walletId
:
number
,
addressIndex
:
number
) {
const
parts
=
formatAmount
(
amount
, { unit:
decimals
, fixed:
2
, fullPrecision:
true
})
!
amount
=
`
${
parts
.
int
}${
parts
.
sep
}${
parts
.
dec
}
`
const
message
=
dir
===
'
in
'
?
`
${
this
.
$t
(
'
common.received
'
)} <strong>${
amount
}</strong> ${
symbol
}
`
:
`
${
this
.
$t
(
'
common.sent
'
)} <strong>${
amount
}</strong> ${
symbol
}
`
this
.
$q
.
notify
({
color:
'
secondary
'
,
message
,
position:
'
top-right
'
,
html:
true
,
timeout:
0
,
group:
false
,
classes:
'
transfer-notify_w100
'
,
actions: [{
label:
this
.
$t
(
'
common.view
'
),
color:
'
white
'
,
handler
: ()
=>
this
.
$router
.
push
({
name:
'
address
'
,
params: {
walletId:
walletId
.
toString
(),
addressIndex:
addressIndex
.
toString
()
}
}).
catch
(()
=>
{ })
}, {
label:
this
.
$t
(
'
common.dismiss
'
),
color:
'
white
'
}]
})
}
},
render(
h
) {
return
h
()
}
})
</
script
>
<
style
>
.transfer-notify_w100
{
width
:
100
%
;
}
</
style
>
Back
|
FazBrowse Home
|
New Git URL