Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Ğecko
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
Ğecko
Commits
2a24c15f
Commit
2a24c15f
authored
4 years ago
by
poka
Browse files
Options
Downloads
Patches
Plain Diff
Cleaner API code
parent
a9d0f5a7
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/api.dart
+38
-32
38 additions, 32 deletions
lib/api.dart
lib/data/currentUD.dart
+0
-10
0 additions, 10 deletions
lib/data/currentUD.dart
lib/main.dart
+9
-10
9 additions, 10 deletions
lib/main.dart
with
47 additions
and
52 deletions
lib/api.dart
+
38
−
32
View file @
2a24c15f
...
...
@@ -4,23 +4,11 @@ import 'package:gql_dio_link/gql_dio_link.dart';
import
'package:gql_exec/gql_exec.dart'
;
import
"package:gql_link/gql_link.dart"
;
// Configure node
const
graphqlEndpoint
=
"https://g1.librelois.fr/gva"
;
const
QcurrentUD
=
"""{
currentUd {
amount
base
}
}"""
;
Future
getBalance
(
String
pubkey
)
async
{
var
qBalance
=
"""{
balance(script: "
$pubkey
") {
amount
base
}
}"""
;
// Build query
Future
buildQ
(
query
)
async
{
final
client
=
dio
.
Dio
();
final
Link
link
=
DioLink
(
graphqlEndpoint
,
...
...
@@ -29,17 +17,45 @@ Future getBalance(String pubkey) async {
final
res
=
await
link
.
request
(
Request
(
operation:
Operation
(
document:
gqlLang
.
parseString
(
q
Balance
)),
operation:
Operation
(
document:
gqlLang
.
parseString
(
q
uery
)),
))
.
first
;
final
balance
=
res
.
data
[
"balance"
][
"amount"
]
/
100
;
return
balance
;
return
res
;
}
/* Requests functions */
// Get current UD
Future
getUD
()
async
{
const
query
=
"""{
currentUd {
amount
base
}
}"""
;
final
result
=
await
buildQ
(
query
);
return
result
.
data
[
"currentUd"
][
"amount"
];
}
// Get balance
Future
getBalance
(
String
pubkey
)
async
{
var
query
=
"""{
balance(script: "
$pubkey
") {
amount
base
}
}"""
;
final
result
=
await
buildQ
(
query
);
return
result
.
data
[
"balance"
][
"amount"
]
/
100
;
}
// Get history
Future
getHistory
(
String
pubkey
)
async
{
print
(
pubkey
);
var
q
Histo
ry
=
"""{
var
q
ue
ry
=
"""{
transactionsHistory(pubkey: "
$pubkey
") {
received {
writtenTime
...
...
@@ -50,18 +66,9 @@ Future getHistory(String pubkey) async {
}
}"""
;
final
client
=
dio
.
Dio
();
final
Link
link
=
DioLink
(
graphqlEndpoint
,
client:
client
,
);
final
res
=
await
link
.
request
(
Request
(
operation:
Operation
(
document:
gqlLang
.
parseString
(
qHistory
)),
))
.
first
;
final
res
=
await
buildQ
(
query
);
// Parse history
var
result
=
res
.
data
[
"transactionsHistory"
][
"received"
];
String
outPubkey
;
for
(
var
bloc
in
result
)
{
...
...
@@ -70,6 +77,5 @@ Future getHistory(String pubkey) async {
print
(
outPubkey
);
}
final
history
=
outPubkey
;
return
history
;
return
outPubkey
;
}
This diff is collapsed.
Click to expand it.
lib/data/currentUD.dart
deleted
100644 → 0
+
0
−
10
View file @
a9d0f5a7
class
TodoFetch
{
static
String
fetchAll
=
"""
query {
currentUd {
amount,
base
}
}
"""
;
}
This diff is collapsed.
Click to expand it.
lib/main.dart
+
9
−
10
View file @
2a24c15f
...
...
@@ -18,13 +18,13 @@ class MyApp extends StatefulWidget {
class
_MyAppState
extends
State
<
MyApp
>
{
Uint8List
bytes
=
Uint8List
(
0
);
TextEditingController
_output
Controller
;
TextEditingController
_output
Pubkey
;
TextEditingController
_outputAmount
;
@override
initState
()
{
super
.
initState
();
this
.
_output
Controller
=
new
TextEditingController
();
this
.
_output
Pubkey
=
new
TextEditingController
();
this
.
_outputAmount
=
new
TextEditingController
();
}
...
...
@@ -43,7 +43,7 @@ class _MyAppState extends State<MyApp> {
children:
<
Widget
>[
SizedBox
(
height:
20
),
TextField
(
controller:
this
.
_output
Controller
,
controller:
this
.
_output
Pubkey
,
maxLines:
2
,
decoration:
InputDecoration
(
prefixIcon:
Icon
(
Icons
.
wrap_text
),
...
...
@@ -120,14 +120,13 @@ class _MyAppState extends State<MyApp> {
print
(
'nothing return.'
);
}
else
{
print
(
"Debug: "
+
barcode
);
this
.
_output
Controller
.
text
=
""
;
this
.
_output
Pubkey
.
text
=
""
;
this
.
_outputAmount
.
text
=
""
;
var
myAmount
=
await
getHistory
(
barcode
.
toString
());
this
.
_outputController
.
text
=
barcode
;
print
(
myAmount
.
toString
());
this
.
_outputAmount
.
text
=
myAmount
.
toString
();
// _getAmount(barcode);
// final udValue = await getUD();
final
myBalance
=
await
getBalance
(
barcode
.
toString
());
this
.
_outputPubkey
.
text
=
barcode
;
print
(
myBalance
.
toString
());
this
.
_outputAmount
.
text
=
myBalance
.
toString
();
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment