Skip to content

Commit acebc30

Browse files
committed
BIT-3589
1 parent 1251660 commit acebc30

File tree

2 files changed

+117
-82
lines changed

2 files changed

+117
-82
lines changed
Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,42 @@
11
class Algorand::AddressController < NetworkController
22
layout 'tabs'
3-
before_action :query_graphql
3+
4+
before_action :query_graphql, only: %i[money_flow]
5+
6+
before_action :set_address
47

58
QUERY_CURRENCIES = BitqueryGraphql::Client.parse <<-'GRAPHQL'
6-
query ( $address: String!){
7-
algorand{
8-
transfers(receiver: {is: $address}, options: {limit: 100}){
9-
currency{
10-
symbol
11-
tokenId
12-
name
13-
}
14-
}
15-
}
16-
}
9+
query ($address: String!){
10+
algorand{
11+
outbound: transfers(receiver: {is: $address}, options: {limit: 100}){
12+
currency{
13+
symbol
14+
tokenId
15+
name
16+
}
17+
}
18+
19+
inbound: transfers(sender: {is: $address}, options: {limit: 100}){
20+
currency{
21+
symbol
22+
tokenId
23+
name
24+
}
25+
}
26+
}
27+
}
1728
GRAPHQL
1829

1930
private
2031

21-
def query_graphql
32+
def set_address
2233
@address = params[:address]
23-
if action_name == 'money_flow'
24-
result = BitqueryGraphql.instance.query_with_retry(QUERY_CURRENCIES, variables: { address: @address }).data.algorand
25-
@currencies = result.transfers.map(&:currency).sort_by { |c| c.token_id == '0' ? 0 : 1 }.uniq { |x| x.token_id } if result.try(:transfers)
26-
end
2734
end
2835

36+
def query_graphql
37+
result = BitqueryGraphql.instance.query_with_retry(QUERY_CURRENCIES, variables: { address: @address }).data.algorand
38+
39+
all_currencies = result.outbound + result.inbound
40+
@currencies = all_currencies.map(&:currency).sort_by { |c| c.token_id == '' ? 0 : 1 }.uniq(&:token_id)
41+
end
2942
end

app/views/algorand/address/money_flow.html.erb

Lines changed: 87 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -20,76 +20,98 @@
2020
</div>
2121
</div>
2222
<script>
23-
$(document).ready(function() {
24-
const query = new graphs.query(`
25-
query ( $address: String!,
26-
$inboundDepth: Int!,
27-
$outboundDepth: Int!,
28-
$limit: Int!,
29-
$currency: Int!,
30-
$from: ISO8601DateTime,
31-
$till: ISO8601DateTime){
32-
algorand{
33-
inbound: coinpath(initialAddress: {is: $address},
34-
currency:{is: $currency},
35-
depth: {lteq: $inboundDepth},
36-
options: {direction: inbound, asc: "depth", desc: "amount", limitBy: {each: "depth", limit: $limit}},
37-
date:{since: $from, till: $till}) {
38-
sender {
39-
address
40-
annotation
41-
}
42-
receiver {
43-
address
44-
annotation
45-
}
46-
amount
47-
currency{symbol}
48-
depth
49-
count
50-
}
23+
const query = new graphs.query(`
24+
query ($address: String!, $inboundDepth: Int!, $outboundDepth: Int!, $limit: Int!, $currency: Int!, $from: ISO8601DateTime, $till: ISO8601DateTime) {
25+
algorand {
26+
inbound: coinpath(
27+
initialAddress: {is: $address}
28+
currency: {is: $currency}
29+
depth: {lteq: $inboundDepth}
30+
options: {direction: inbound, asc: "depth", desc: "amount", limitBy: {each: "depth", limit: $limit}}
31+
date: {since: $from, till: $till}
32+
) {
33+
sender {
34+
address
35+
annotation
36+
}
37+
receiver {
38+
address
39+
annotation
40+
}
41+
amount
42+
currency {
43+
symbol
44+
}
45+
depth
46+
count
47+
}
48+
outbound: coinpath(
49+
initialAddress: {is: $address}
50+
currency: {is: $currency}
51+
depth: {lteq: $outboundDepth}
52+
options: {asc: "depth", desc: "amount", limitBy: {each: "depth", limit: $limit}}
53+
date: {since: $from, till: $till}
54+
) {
55+
sender {
56+
address
57+
annotation
58+
}
59+
receiver {
60+
address
61+
annotation
62+
}
63+
amount
64+
currency {
65+
symbol
66+
}
67+
depth
68+
count
69+
}
70+
}
71+
}
72+
`)
5173

74+
new graphs.address_graph('#graph', query, {
75+
theme: '<%= @theme %>',
76+
})
5277

53-
outbound: coinpath(initialAddress: {is: $address},
54-
currency:{is: $currency},
55-
depth: {lteq: $outboundDepth},
56-
options: {asc: "depth", desc: "amount", limitBy: {each: "depth", limit: $limit}},
57-
date:{since: $from, till: $till}) {
58-
sender {
59-
address
60-
annotation
61-
}
62-
receiver {
63-
address
64-
annotation
65-
}
66-
amount
67-
currency{symbol}
68-
depth
69-
count
70-
}
71-
}
72-
}`)
73-
window.query = query
74-
new graphs.address_graph('#graph', query, {
75-
theme: '<%= @theme %>',
76-
})
78+
new graphs.addControls('#graph', query, {
79+
theme: '<%= @theme %>',
80+
currencies: [
81+
<%= @currencies.collect do |cur|
82+
value = cur.token_id == '' ? 0 : cur.token_id
7783

78-
new graphs.addControls('#graph', query, {
79-
theme: '<%= @theme %>',
80-
currencies: [<%= @currencies.collect{|cur| "{token_id:#{cur.token_id},symbol:\"#{cur.symbol}\",name:\"#{cur.name}\",search:#{cur.token_id}}"}.join(',').html_safe %>],
81-
})
84+
"{token_id:\"#{cur.token_id}\",symbol:\"#{cur.symbol}\",name:\"#{cur.name}\",search:\"#{value}\"}"
85+
end.join(',').html_safe %>
86+
]
87+
})
8288

83-
new graphs.address_sankey('#sankey-graph', query, {
84-
theme: '<%= @theme %>',
85-
})
89+
new graphs.address_sankey('#sankey-graph', query, {
90+
theme: '<%= @theme %>',
91+
})
8692

87-
new graphs.addControls('#sankey-graph', query, {
88-
theme: '<%= @theme %>',
89-
currencies: [<%= @currencies.collect{|cur| "{token_id:#{cur.token_id},symbol:\"#{cur.symbol}\",name:\"#{cur.name}\",search:#{cur.token_id}}"}.join(',').html_safe %>],
90-
})
93+
new graphs.addControls('#sankey-graph', query, {
94+
theme: '<%= @theme %>',
95+
currencies: [
96+
<%= @currencies.collect do |cur|
97+
value = cur.token_id == '' ? 0 : cur.token_id
9198

92-
queryWithTimeRange(rr, query, <%= @from.html_safe %>, <%= @till.html_safe %>, {"inboundDepth": 1, "outboundDepth": 1, "limit": 10, "offset": 0, "network": "<%= params['network']['network'] %>", "address": "<%= @address %>", "currency": <%= @currencies.first && @currencies.first.token_id || 0 %>})
93-
})
99+
"{token_id:\"#{value}\",symbol:\"#{cur.symbol}\",name:\"#{cur.name}\",search:\"#{value}\"}"
100+
end.join(',').html_safe %>
101+
]
102+
})
103+
104+
queryWithTimeRange(rr, query, <%= @from.html_safe %>, <%= @till.html_safe %>, {
105+
"inboundDepth": 1,
106+
"outboundDepth": 1,
107+
"limit": 10,
108+
"offset": 0,
109+
"network": "<%= params['network']['network'] %>",
110+
"address": "<%= @address %>",
111+
"currency": <%= @currencies&.first&.token_id.present? || 0 %>,
112+
})
94113
</script>
95114
</div>
115+
116+
117+

0 commit comments

Comments
 (0)