Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ginkgo
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
vjrj
ginkgo
Commits
625e8a38
Commit
625e8a38
authored
1 year ago
by
vjrj
Browse files
Options
Downloads
Patches
Plain Diff
Added retry to gva.history
parent
a8bd63fc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/data/models/transaction_cubit.dart
+1
-1
1 addition, 1 deletion
lib/data/models/transaction_cubit.dart
lib/g1/api.dart
+25
-35
25 additions, 35 deletions
lib/g1/api.dart
lib/ui/widgets/fourth_screen/transaction_page.dart
+99
-96
99 additions, 96 deletions
lib/ui/widgets/fourth_screen/transaction_page.dart
with
125 additions
and
132 deletions
lib/data/models/transaction_cubit.dart
+
1
−
1
View file @
625e8a38
...
...
@@ -31,7 +31,7 @@ class TransactionsCubit extends HydratedCubit<TransactionsAndBalanceState> {
Future
<
void
>
fetchTransactions
(
NodeListCubit
cubit
)
async
{
logger
(
'Loading transactions'
);
final
Map
<
String
,
dynamic
>
?
txData
=
await
gva
()
.
h
istory
(
SharedPreferencesHelper
()
.
getPubKey
());
await
gva
H
istory
AndBalance
(
SharedPreferencesHelper
()
.
getPubKey
());
if
(
txData
==
null
)
{
logger
(
'Failed to get transactions'
);
return
;
...
...
This diff is collapsed.
Click to expand it.
lib/g1/api.dart
+
25
−
35
View file @
625e8a38
...
...
@@ -411,10 +411,7 @@ Future<String> pay(
final
String
node
=
output
;
try
{
final
Gva
gva
=
Gva
(
node:
node
);
logger
(
'Trying
$node
to get balance'
);
final
CesiumWallet
wallet
=
await
SharedPreferencesHelper
()
.
getWallet
();
logger
(
'Current balance
${await gva.balance(wallet.pubkey)}
'
);
// logger('Current balance ${await gva.balance(wallet.pubkey)}');
logger
(
'Trying
$node
to send
$amount
to
$to
with comment
${comment ?? ''}
'
);
...
...
@@ -448,40 +445,33 @@ String getGvaNode() {
}
}
Future
<
double
>
gvaBalance
()
async
{
final
String
output
=
getGvaNode
();
if
(
Uri
.
tryParse
(
output
)
!=
null
)
{
final
String
node
=
output
;
try
{
final
Gva
gva
=
Gva
(
node:
node
);
logger
(
'Trying
$node
to get balance'
);
final
String
pubKey
=
SharedPreferencesHelper
()
.
getPubKey
();
final
double
balance
=
await
gva
.
balance
(
pubKey
);
logger
(
'Current balance
$balance
'
);
return
balance
;
}
catch
(
e
,
stacktrace
)
{
// move logger outside main
logger
(
e
);
logger
(
stacktrace
);
throw
Exception
(
'Oops! failed to obtain balance'
);
}
Future
<
Map
<
String
,
dynamic
>
?
>
gvaHistoryAndBalance
(
String
pubKey
)
async
{
final
List
<
Node
>
nodes
=
NodeManager
()
.
nodeList
(
NodeType
.
gva
);
if
(
nodes
.
isEmpty
)
{
nodes
.
addAll
(
defaultGvaNodes
);
}
throw
Exception
(
'Sorry: I cannot find a working node to get your balance'
);
}
Gva
gva
()
{
final
String
output
=
getGvaNode
();
if
(
Uri
.
tryParse
(
output
)
!=
null
)
{
final
String
node
=
output
;
for
(
int
i
=
0
;
i
<
nodes
.
length
;
i
++
)
{
final
Node
node
=
nodes
[
i
];
if
(
node
.
errors
>
=
NodeManager
.
maxNodeErrors
)
{
logger
(
'Too much errors skip
${node.url}
'
);
continue
;
}
try
{
final
Gva
gva
=
Gva
(
node:
node
);
return
gva
;
}
catch
(
e
,
stacktrace
)
{
// move logger outside main
logger
(
e
);
logger
(
stacktrace
);
throw
Exception
(
'Oops! failed to obtain balance'
);
final
String
output
=
getGvaNode
();
if
(
Uri
.
tryParse
(
output
)
!=
null
)
{
final
String
node
=
output
;
final
Gva
gva
=
Gva
(
node:
node
);
final
Map
<
String
,
dynamic
>
?
result
=
await
gva
.
history
(
pubKey
);
return
result
;
}
}
catch
(
e
)
{
logger
(
'Error trying
${node.url}
$e
'
);
logger
(
'Increasing node errors of
${node.url}
(
${node.errors}
)'
);
NodeManager
()
.
updateNode
(
NodeType
.
gva
,
node
.
copyWith
(
errors:
node
.
errors
+
1
));
continue
;
}
}
throw
Exception
(
'Sorry: I cannot find a working node to get your balance'
);
throw
Exception
(
'Sorry: I cannot find a working node to get your transactions'
);
}
This diff is collapsed.
Click to expand it.
lib/ui/widgets/fourth_screen/transaction_page.dart
+
99
−
96
View file @
625e8a38
...
...
@@ -11,7 +11,6 @@ import '../../../data/models/transaction.dart';
import
'../../../data/models/transaction_cubit.dart'
;
import
'../../../shared_prefs.dart'
;
import
'../../ui_helpers.dart'
;
import
'../loading_box.dart'
;
import
'transaction_chart.dart'
;
import
'transaction_item.dart'
;
...
...
@@ -52,20 +51,18 @@ class _TransactionsAndBalanceWidgetState
if
(
/* _transScrollController.position.pixels ==
_transScrollController.position.maxScrollExtent || */
_transScrollController
.
offset
==
0
)
{
await
_refreshTransactions
();
// await _refreshTransactions();
_refreshIndicatorKey
.
currentState
?.
show
();
}
}
Future
<
void
>
_refreshTransactions
()
async
{
setState
(()
{
isLoading
=
true
;
});
await
transCubit
.
fetchTransactions
(
nodeListCubit
);
setState
(()
{
isLoading
=
false
;
});
return
transCubit
.
fetchTransactions
(
nodeListCubit
);
}
final
GlobalKey
<
RefreshIndicatorState
>
_refreshIndicatorKey
=
GlobalKey
<
RefreshIndicatorState
>();
@override
Widget
build
(
BuildContext
context
)
{
final
String
myPubKey
=
SharedPreferencesHelper
()
.
getPubKey
();
...
...
@@ -76,67 +73,70 @@ class _TransactionsAndBalanceWidgetState
final
ContactsCubit
contactsCubit
=
context
.
read
<
ContactsCubit
>();
final
List
<
Transaction
>
transactions
=
transBalanceState
.
transactions
;
final
double
balance
=
transBalanceState
.
balance
;
if
(
!
isLoading
)
{
return
Backdrop
Scaffold
(
appBar:
BackdropAppBar
(
backgroundColor:
Theme
.
of
(
context
)
.
colorScheme
.
inversePrimary
,
title:
Text
(
tr
(
'balance'
)),
actions:
<
Widget
>[
I
con
Button
(
icon:
const
Icon
(
Icons
.
refresh
),
onPressed:
()
{
_refreshTransactions
();
},
),
const
BackdropToggleButton
(
// The default
// icon: AnimatedIcons.close_menu,
)
],
),
backLayer:
Center
(
child:
Container
(
decoration:
BoxDecoration
(
color:
Theme
.
of
(
context
)
.
colorScheme
.
inversePrimary
,
border:
Border
.
all
(
color:
Theme
.
of
(
context
)
.
colorScheme
.
inversePrimary
,
width:
3
),
/* borderRadius: const BorderRadius.only(
return
BackdropScaffold
(
appBar:
Backdrop
AppBar
(
backgroundColor:
Theme
.
of
(
context
)
.
colorScheme
.
inversePrimary
,
title:
Text
(
tr
(
'balance'
))
,
actions:
<
Widget
>[
IconButton
(
i
con
:
const
Icon
(
Icons
.
refresh
),
onPressed:
()
{
_refreshIndicatorKey
.
currentState
?.
show
();
//
_refreshTransactions();
},
),
const
BackdropToggleButton
(
// The default
// icon: AnimatedIcons.close_menu,
)
],
),
backLayer:
Center
(
child:
Container
(
decoration:
BoxDecoration
(
color:
Theme
.
of
(
context
)
.
colorScheme
.
inversePrimary
,
border:
Border
.
all
(
color:
Theme
.
of
(
context
)
.
colorScheme
.
inversePrimary
,
width:
3
),
/* borderRadius: const BorderRadius.only(
topLeft: Radius.circular(8),
topRight: Radius.circular(8),
), */
),
child:
Scrollbar
(
child:
ListView
(
// controller: scrollController,
children:
<
Widget
>[
Padding
(
padding:
const
EdgeInsets
.
symmetric
(
vertical:
10.0
),
child:
Center
(
child:
Text
(
formatKAmount
(
context
,
balance
),
style:
TextStyle
(
fontSize:
36.0
,
color:
balance
==
0
?
Colors
.
lightBlue
:
Colors
.
lightBlue
,
fontWeight:
FontWeight
.
bold
),
)),
),
if
(
!
kReleaseMode
)
TransactionChart
()
/*BalanceChart(
),
child:
Scrollbar
(
child:
ListView
(
// controller: scrollController,
children:
<
Widget
>[
Padding
(
padding:
const
EdgeInsets
.
symmetric
(
vertical:
10.0
),
child:
Center
(
child:
Text
(
formatKAmount
(
context
,
balance
),
style:
TextStyle
(
fontSize:
36.0
,
color:
balance
==
0
?
Colors
.
lightBlue
:
Colors
.
lightBlue
,
fontWeight:
FontWeight
.
bold
),
)),
),
if
(
!
kReleaseMode
)
TransactionChart
()
/*BalanceChart(
transactions: .transactions),*/
],
)),
],
)),
subHeader:
BackdropSubHeader
(
title:
Text
(
tr
(
'transactions'
)),
)),
subHeader:
BackdropSubHeader
(
title:
Text
(
tr
(
'transactions'
)),
divider:
Divider
(
color:
Theme
.
of
(
context
)
.
colorScheme
.
surfaceVariant
,
height:
0
,
),
frontLayer:
Center
(
child:
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
<
Widget
>[
/* Container(
),
frontLayer:
Center
(
child:
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
<
Widget
>[
/* Container(
/* color: Theme
.of(context)
.colorScheme
...
...
@@ -146,31 +146,37 @@ class _TransactionsAndBalanceWidgetState
child:
const
Padding
(
padding:
EdgeInsets
.
symmetric
(
horizontal:
16
),
child:
Header
(
text:
'transactions'
))),
*/
Expanded
(
Expanded
(
child:
Padding
(
padding:
const
EdgeInsets
.
fromLTRB
(
0
,
0
,
0
,
50
),
child:
transactions
.
isEmpty
?
Padding
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
20
),
child:
Center
(
child:
Text
(
tr
(
'no_transactions'
))))
:
ListView
.
builder
(
physics:
const
AlwaysScrollableScrollPhysics
(),
shrinkWrap:
true
,
controller:
_transScrollController
,
itemCount:
transactions
.
length
,
// Size of elements
// itemExtent: 100,
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
TransactionListItem
(
index:
index
,
transaction:
transactions
[
index
],
avatar:
avatar
(
null
),
);
/*
padding:
const
EdgeInsets
.
fromLTRB
(
0
,
0
,
0
,
50
),
child:
transactions
.
isEmpty
?
Padding
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
20
),
child:
Center
(
child:
Text
(
tr
(
'no_transactions'
))))
:
RefreshIndicator
(
key:
_refreshIndicatorKey
,
color:
Colors
.
white
,
backgroundColor:
Theme
.
of
(
context
)
.
colorScheme
.
primary
,
strokeWidth:
4.0
,
onRefresh:
()
async
{
return
_refreshTransactions
();
},
// Pull from top to show refresh indicator.
child:
ListView
.
builder
(
physics:
const
AlwaysScrollableScrollPhysics
(),
shrinkWrap:
true
,
controller:
_transScrollController
,
itemCount:
transactions
.
length
,
// Size of elements
// itemExtent: 100,
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
TransactionListItem
(
index:
index
,
transaction:
transactions
[
index
],
avatar:
avatar
(
null
),
);
/*
Slidable(
// Specify a key if the Slidable is dismissible.
...
...
@@ -238,14 +244,11 @@ class _TransactionsAndBalanceWidgetState
: Colors.blue)),
));
*/
},
)),
)
]),
));
}
else
{
return
const
LoadingScreen
();
}
},
)),
))
]),
));
});
}
...
...
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