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
e8acbd2c
Commit
e8acbd2c
authored
1 year ago
by
vjrj
Browse files
Options
Downloads
Patches
Plain Diff
Pay fail with retry message if faulty balance
parent
635e0a18
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
assets/translations/en.json
+2
-1
2 additions, 1 deletion
assets/translations/en.json
assets/translations/es.json
+2
-1
2 additions, 1 deletion
assets/translations/es.json
lib/ui/screens/pay_form.dart
+59
-39
59 additions, 39 deletions
lib/ui/screens/pay_form.dart
with
63 additions
and
41 deletions
assets/translations/en.json
+
2
−
1
View file @
e8acbd2c
...
...
@@ -119,5 +119,6 @@
"long_press_to_edit"
:
"Tap and hold to edit"
,
"form_contact_pub_key"
:
"Public key"
,
"payment_error"
:
"Payment error"
,
"payment_error_desc"
:
"Oops! the payment failed. More details: {error}"
"payment_error_desc"
:
"Oops! the payment failed. More details: {error}"
,
"payment_error_retry"
:
"Oops! the payment failed. Please retry in some minutes."
}
This diff is collapsed.
Click to expand it.
assets/translations/es.json
+
2
−
1
View file @
e8acbd2c
...
...
@@ -119,5 +119,6 @@
"form_contact_pub_key"
:
"Clave pública"
,
"reloading_nodes"
:
"Refrescando nodos del tipo {type}"
,
"payment_error"
:
"Error en el pago"
,
"payment_error_desc"
:
"¡Vaya! el pago falló. Más detalles: {error}"
"payment_error_desc"
:
"¡Vaya! el pago falló. Más detalles: {error}"
,
"payment_error_retry"
:
"¡Vaya! el pago falló. Inténtalo de nuevo en unos minutos"
}
This diff is collapsed.
Click to expand it.
lib/ui/screens/pay_form.dart
+
59
−
39
View file @
e8acbd2c
...
...
@@ -77,45 +77,11 @@ class _PayFormState extends State<PayForm> {
!
_weHaveBalance
(
context
,
state
.
amount
!
))
?
null
:
()
async
{
// We disable the number, anyway
context
.
read
<
PaymentCubit
>()
.
sending
();
final
String
contactPubKey
=
state
.
contact
!.
pubKey
;
final
bool
?
confirmed
=
await
_confirmSend
(
context
,
state
.
amount
.
toString
(),
humanizePubKey
(
contactPubKey
));
if
(
!
mounted
)
{
return
;
}
if
(
confirmed
==
null
||
!
confirmed
)
{
context
.
read
<
PaymentCubit
>()
.
sentFailed
();
}
else
{
final
String
response
=
await
pay
(
to:
contactPubKey
,
comment:
state
.
comment
,
amount:
state
.
amount
!
);
if
(
!
mounted
)
{
// Cannot show a tooltip if the widget is not now visible
return
;
}
if
(
response
==
'success'
)
{
context
.
read
<
PaymentCubit
>()
.
sent
();
showTooltip
(
context
,
tr
(
'payment_successful'
),
tr
(
'payment_successful_desc'
));
}
else
{
showTooltip
(
context
,
tr
(
'payment_error'
),
tr
(
'payment_error_desc'
,
namedArgs:
<
String
,
String
>{
// We try to translate the error, like "insufficient balance"
'error'
:
tr
(
response
)
}));
context
.
read
<
PaymentCubit
>()
.
sentFailed
();
// Shuffle the nodes so we can retry with other
context
.
read
<
NodeListCubit
>()
.
shuffle
(
NodeType
.
gva
);
// FIXME - retry manually with other node
}
try
{
await
payWithRetry
(
context
,
state
,
false
);
}
on
RetryException
{
// Here the transactions can be lost, so we must implement some manual retry use
await
payWithRetry
(
context
,
state
,
true
);
}
},
style:
ElevatedButton
.
styleFrom
(
...
...
@@ -181,6 +147,60 @@ class _PayFormState extends State<PayForm> {
},
);
}
Future
<
void
>
payWithRetry
(
BuildContext
context
,
PaymentState
state
,
bool
useMempool
)
async
{
logger
(
'Trying to pay state with useMempool:
$useMempool
'
);
// We disable the number, anyway
context
.
read
<
PaymentCubit
>()
.
sending
();
final
String
contactPubKey
=
state
.
contact
!.
pubKey
;
final
bool
?
confirmed
=
await
_confirmSend
(
context
,
state
.
amount
.
toString
(),
humanizePubKey
(
contactPubKey
));
if
(
!
mounted
)
{
return
;
}
if
(
confirmed
==
null
||
!
confirmed
)
{
context
.
read
<
PaymentCubit
>()
.
sentFailed
();
}
else
{
final
String
response
=
await
pay
(
to:
contactPubKey
,
comment:
state
.
comment
,
amount:
state
.
amount
!
);
if
(
!
mounted
)
{
// Cannot show a tooltip if the widget is not now visible
return
;
}
if
(
response
==
'success'
)
{
context
.
read
<
PaymentCubit
>()
.
sent
();
showTooltip
(
context
,
tr
(
'payment_successful'
),
tr
(
'payment_successful_desc'
));
}
else
{
/* this retry didn't work
if (!useMempool) {
throw RetryException();
} */
final
bool
failedWithBalance
=
response
==
'insufficient balance'
&&
_weHaveBalance
(
context
,
state
.
amount
!
);
showPayError
(
context
,
failedWithBalance
?
tr
(
'payment_error_retry'
)
:
tr
(
'payment_error_desc'
,
namedArgs:
<
String
,
String
>{
// We try to translate the error, like "insufficient balance"
'error'
:
tr
(
response
)
}));
}
}
}
void
showPayError
(
BuildContext
context
,
String
desc
)
{
showTooltip
(
context
,
tr
(
'payment_error'
),
desc
);
context
.
read
<
PaymentCubit
>()
.
sentFailed
();
// Shuffle the nodes so we can retry with other
context
.
read
<
NodeListCubit
>()
.
shuffle
(
NodeType
.
gva
,
true
);
}
}
class
RetryException
implements
Exception
{
RetryException
();
}
class
NoNewLineTextInputFormatter
extends
TextInputFormatter
{
...
...
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