Skip to content

Commit a06d7c1

Browse files
authored
Merge pull request #1643 from gluneau/localization/core-swaps
feat: localization of core/swaps
2 parents d359687 + 70fe172 commit a06d7c1

7 files changed

Lines changed: 506 additions & 46 deletions

File tree

lib/core/swaps/domain/entity/swap.dart

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import 'package:bb_mobile/core/settings/domain/settings_entity.dart';
2+
import 'package:bb_mobile/core/utils/build_context_x.dart';
23
import 'package:bb_mobile/core/utils/constants.dart';
34
import 'package:bb_mobile/core/utils/percentage.dart';
45
import 'package:bb_mobile/core/utils/string_formatting.dart';
56
import 'package:bolt11_decoder/bolt11_decoder.dart';
67
import 'package:decimal/decimal.dart';
8+
import 'package:flutter/material.dart';
79
import 'package:freezed_annotation/freezed_annotation.dart';
810

911
part 'swap.freezed.dart';
@@ -38,21 +40,21 @@ enum SwapStatus {
3840
expired,
3941
failed;
4042

41-
String get displayName {
43+
String displayName(BuildContext context) {
4244
switch (this) {
4345
case SwapStatus.pending:
44-
return 'Pending';
46+
return context.loc.coreSwapsStatusPending;
4547
case SwapStatus.paid:
4648
case SwapStatus.claimable:
4749
case SwapStatus.refundable:
4850
case SwapStatus.canCoop:
49-
return 'In Progress';
51+
return context.loc.coreSwapsStatusInProgress;
5052
case SwapStatus.completed:
51-
return 'Completed';
53+
return context.loc.coreSwapsStatusCompleted;
5254
case SwapStatus.expired:
53-
return 'Expired';
55+
return context.loc.coreSwapsStatusExpired;
5456
case SwapStatus.failed:
55-
return 'Failed';
57+
return context.loc.coreSwapsStatusFailed;
5658
}
5759
}
5860
}
@@ -311,13 +313,13 @@ sealed class Swap with _$Swap {
311313
bool get isChainSwapExternal =>
312314
this is ChainSwap && (this as ChainSwap).receiveWalletId == null;
313315

314-
String get swapAction =>
316+
String swapAction(BuildContext context) =>
315317
status == SwapStatus.claimable
316-
? 'Claim'
318+
? context.loc.coreSwapsActionClaim
317319
: status == SwapStatus.canCoop
318-
? 'Close'
320+
? context.loc.coreSwapsActionClose
319321
: status == SwapStatus.refundable
320-
? 'Refund'
322+
? context.loc.coreSwapsActionRefund
321323
: '';
322324

323325
bool get swapCompleted => status == SwapStatus.completed;
@@ -426,82 +428,82 @@ class Invoice {
426428
}
427429

428430
extension SwapStatusMessage on Swap {
429-
String getDisplayMessage() {
431+
String getDisplayMessage(BuildContext context) {
430432
if (isLnReceiveSwap) {
431433
switch (status) {
432434
case SwapStatus.pending:
433-
return "Swap is not yet initialized.";
435+
return context.loc.coreSwapsLnReceivePending;
434436
case SwapStatus.paid:
435-
return "Sender has paid the invoice.";
437+
return context.loc.coreSwapsLnReceivePaid;
436438
case SwapStatus.claimable:
437-
return "Swap is ready to be claimed.";
439+
return context.loc.coreSwapsLnReceiveClaimable;
438440
case SwapStatus.refundable:
439-
return "Swap is ready to be refunded.";
441+
return context.loc.coreSwapsLnReceiveRefundable;
440442
case SwapStatus.canCoop:
441-
return "Swap will complete momentarily.";
443+
return context.loc.coreSwapsLnReceiveCanCoop;
442444
case SwapStatus.completed:
443-
return "Swap is completed.";
445+
return context.loc.coreSwapsLnReceiveCompleted;
444446
case SwapStatus.expired:
445-
return "Swap Expired.";
447+
return context.loc.coreSwapsLnReceiveExpired;
446448
case SwapStatus.failed:
447-
return "Swap Failed.";
449+
return context.loc.coreSwapsLnReceiveFailed;
448450
}
449451
} else if (isLnSendSwap) {
450452
switch (status) {
451453
case SwapStatus.pending:
452-
return "Swap is not yet initialized.";
454+
return context.loc.coreSwapsLnSendPending;
453455
case SwapStatus.paid:
454-
return "Invoice will be paid after you payment receives confirmation.";
456+
return context.loc.coreSwapsLnSendPaid;
455457
case SwapStatus.claimable:
456-
return "Swap is ready to be claimed.";
458+
return context.loc.coreSwapsLnSendClaimable;
457459
case SwapStatus.refundable:
458-
return "Swap is ready to be refunded.";
460+
return context.loc.coreSwapsLnSendRefundable;
459461
case SwapStatus.canCoop:
460-
return "Swap will complete momentarily.";
462+
return context.loc.coreSwapsLnSendCanCoop;
461463
case SwapStatus.completed:
462464
final swap = this;
463465
if (swap is LnSendSwap && swap.refundTxid != null) {
464-
return "Swap has been refunded.";
466+
return context.loc.coreSwapsLnSendCompletedRefunded;
465467
} else {
466-
return "Swap is completed successfully.";
468+
return context.loc.coreSwapsLnSendCompletedSuccess;
467469
}
468470
case SwapStatus.expired:
469-
return "Swap Expired";
471+
return context.loc.coreSwapsLnSendExpired;
470472
case SwapStatus.failed:
471473
final swap = this;
472474
if (swap is LnSendSwap && swap.sendTxid != null) {
473-
return "Swap will be refunded shortly.";
475+
return context.loc.coreSwapsLnSendFailedRefunding;
474476
} else {
475-
return "Swap Failed.";
477+
return context.loc.coreSwapsLnSendFailed;
476478
}
477479
}
478480
} else if (isChainSwap) {
479481
switch (status) {
480482
case SwapStatus.pending:
481-
return "Transfer is not yet initialized.";
483+
return context.loc.coreSwapsChainPending;
482484
case SwapStatus.paid:
483-
return "Waiting for transfer provider's payment to receive confirmation. This may take a while to complete.";
485+
return context.loc.coreSwapsChainPaid;
484486
case SwapStatus.claimable:
485-
return "Transfer is ready to be claimed.";
487+
return context.loc.coreSwapsChainClaimable;
486488
case SwapStatus.refundable:
487-
return "Transfer is ready to be refunded.";
489+
return context.loc.coreSwapsChainRefundable;
488490
case SwapStatus.canCoop:
489-
return "Transfer will complete momentarily.";
491+
return context.loc.coreSwapsChainCanCoop;
490492
case SwapStatus.completed:
491493
final swap = this;
492494
if (swap is ChainSwap && swap.refundTxid != null) {
493-
return "Transfer has been refunded.";
495+
return context.loc.coreSwapsChainCompletedRefunded;
494496
} else {
495-
return "Transfer is completed successfully.";
497+
return context.loc.coreSwapsChainCompletedSuccess;
496498
}
497499
case SwapStatus.expired:
498-
return "Transfer Expired";
500+
return context.loc.coreSwapsChainExpired;
499501
case SwapStatus.failed:
500502
final swap = this;
501503
if (swap is ChainSwap && swap.sendTxid != null) {
502-
return "Transfer will be refunded shortly.";
504+
return context.loc.coreSwapsChainFailedRefunding;
503505
} else {
504-
return "Transfer Failed.";
506+
return context.loc.coreSwapsChainFailed;
505507
}
506508
}
507509
}

lib/core/wallet/domain/entities/wallet_transaction.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import 'package:bb_mobile/core/utils/build_context_x.dart';
12
import 'package:bb_mobile/core/wallet/domain/entities/transaction_input.dart';
23
import 'package:bb_mobile/core/wallet/domain/entities/transaction_output.dart';
34
import 'package:bb_mobile/core/wallet/domain/entities/wallet.dart';
5+
import 'package:flutter/material.dart';
46
import 'package:freezed_annotation/freezed_annotation.dart';
57

68
part 'wallet_transaction.freezed.dart';
@@ -11,12 +13,12 @@ enum WalletTransactionStatus {
1113
pending,
1214
confirmed;
1315

14-
String get displayName {
16+
String displayName(BuildContext context) {
1517
switch (this) {
1618
case WalletTransactionStatus.pending:
17-
return 'Pending';
19+
return context.loc.coreWalletTransactionStatusPending;
1820
case WalletTransactionStatus.confirmed:
19-
return 'Confirmed';
21+
return context.loc.coreWalletTransactionStatusConfirmed;
2022
}
2123
}
2224
}

lib/features/transactions/ui/screens/transaction_details_screen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class TransactionDetailsScreen extends StatelessWidget {
5555
final isOrderType = tx?.isOrder == true;
5656
final walletTransaction = tx?.walletTransaction;
5757
final swap = tx?.swap;
58-
final swapAction = swap?.swapAction ?? '';
58+
final swapAction = swap?.swapAction(context) ?? '';
5959
final isChainSwap = swap?.isChainSwap ?? false;
6060
final retryingSwap = context.select(
6161
(TransactionDetailsCubit bloc) => bloc.state.retryingSwap,

lib/features/transactions/ui/widgets/transaction_details_table.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class TransactionDetailsTable extends StatelessWidget {
184184
),
185185
DetailsTableItem(
186186
label: context.loc.transactionDetailLabelStatus,
187-
displayValue: walletTransaction.status.displayName,
187+
displayValue: walletTransaction.status.displayName(context),
188188
),
189189
if (walletTransaction.confirmationTime != null)
190190
DetailsTableItem(
@@ -740,9 +740,9 @@ class TransactionDetailsTable extends StatelessWidget {
740740
swap.isLnSendSwap &&
741741
(swap as LnSendSwap).refundTxid != null)
742742
? context.loc.transactionDetailLabelRefunded
743-
: swap.status.displayName,
743+
: swap.status.displayName(context),
744744
expandableChild: BBText(
745-
swap.getDisplayMessage(),
745+
swap.getDisplayMessage(context),
746746
style: context.font.bodySmall?.copyWith(
747747
color: context.appColors.secondary,
748748
),

localization/app_en.arb

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,158 @@
2727
}
2828
}
2929
},
30+
"coreSwapsStatusPending": "Pending",
31+
"@coreSwapsStatusPending": {
32+
"description": "Display name for pending swap status"
33+
},
34+
"coreSwapsStatusInProgress": "In Progress",
35+
"@coreSwapsStatusInProgress": {
36+
"description": "Display name for in-progress swap status (paid, claimable, refundable, canCoop)"
37+
},
38+
"coreSwapsStatusCompleted": "Completed",
39+
"@coreSwapsStatusCompleted": {
40+
"description": "Display name for completed swap status"
41+
},
42+
"coreSwapsStatusExpired": "Expired",
43+
"@coreSwapsStatusExpired": {
44+
"description": "Display name for expired swap status"
45+
},
46+
"coreSwapsStatusFailed": "Failed",
47+
"@coreSwapsStatusFailed": {
48+
"description": "Display name for failed swap status"
49+
},
50+
"coreSwapsActionClaim": "Claim",
51+
"@coreSwapsActionClaim": {
52+
"description": "Action label for claiming a swap"
53+
},
54+
"coreSwapsActionClose": "Close",
55+
"@coreSwapsActionClose": {
56+
"description": "Action label for closing a swap cooperatively"
57+
},
58+
"coreSwapsActionRefund": "Refund",
59+
"@coreSwapsActionRefund": {
60+
"description": "Action label for refunding a swap"
61+
},
62+
"coreSwapsLnReceivePending": "Swap is not yet initialized.",
63+
"@coreSwapsLnReceivePending": {
64+
"description": "Status message for pending Lightning receive swap"
65+
},
66+
"coreSwapsLnReceivePaid": "Sender has paid the invoice.",
67+
"@coreSwapsLnReceivePaid": {
68+
"description": "Status message for paid Lightning receive swap"
69+
},
70+
"coreSwapsLnReceiveClaimable": "Swap is ready to be claimed.",
71+
"@coreSwapsLnReceiveClaimable": {
72+
"description": "Status message for claimable Lightning receive swap"
73+
},
74+
"coreSwapsLnReceiveRefundable": "Swap is ready to be refunded.",
75+
"@coreSwapsLnReceiveRefundable": {
76+
"description": "Status message for refundable Lightning receive swap"
77+
},
78+
"coreSwapsLnReceiveCanCoop": "Swap will complete momentarily.",
79+
"@coreSwapsLnReceiveCanCoop": {
80+
"description": "Status message for Lightning receive swap that can complete cooperatively"
81+
},
82+
"coreSwapsLnReceiveCompleted": "Swap is completed.",
83+
"@coreSwapsLnReceiveCompleted": {
84+
"description": "Status message for completed Lightning receive swap"
85+
},
86+
"coreSwapsLnReceiveExpired": "Swap Expired.",
87+
"@coreSwapsLnReceiveExpired": {
88+
"description": "Status message for expired Lightning receive swap"
89+
},
90+
"coreSwapsLnReceiveFailed": "Swap Failed.",
91+
"@coreSwapsLnReceiveFailed": {
92+
"description": "Status message for failed Lightning receive swap"
93+
},
94+
"coreSwapsLnSendPending": "Swap is not yet initialized.",
95+
"@coreSwapsLnSendPending": {
96+
"description": "Status message for pending Lightning send swap"
97+
},
98+
"coreSwapsLnSendPaid": "Invoice will be paid after your payment receives confirmation.",
99+
"@coreSwapsLnSendPaid": {
100+
"description": "Status message for paid Lightning send swap"
101+
},
102+
"coreSwapsLnSendClaimable": "Swap is ready to be claimed.",
103+
"@coreSwapsLnSendClaimable": {
104+
"description": "Status message for claimable Lightning send swap"
105+
},
106+
"coreSwapsLnSendRefundable": "Swap is ready to be refunded.",
107+
"@coreSwapsLnSendRefundable": {
108+
"description": "Status message for refundable Lightning send swap"
109+
},
110+
"coreSwapsLnSendCanCoop": "Swap will complete momentarily.",
111+
"@coreSwapsLnSendCanCoop": {
112+
"description": "Status message for Lightning send swap that can complete cooperatively"
113+
},
114+
"coreSwapsLnSendCompletedRefunded": "Swap has been refunded.",
115+
"@coreSwapsLnSendCompletedRefunded": {
116+
"description": "Status message for Lightning send swap completed via refund"
117+
},
118+
"coreSwapsLnSendCompletedSuccess": "Swap is completed successfully.",
119+
"@coreSwapsLnSendCompletedSuccess": {
120+
"description": "Status message for successfully completed Lightning send swap"
121+
},
122+
"coreSwapsLnSendExpired": "Swap Expired",
123+
"@coreSwapsLnSendExpired": {
124+
"description": "Status message for expired Lightning send swap"
125+
},
126+
"coreSwapsLnSendFailedRefunding": "Swap will be refunded shortly.",
127+
"@coreSwapsLnSendFailedRefunding": {
128+
"description": "Status message for failed Lightning send swap that will be refunded"
129+
},
130+
"coreSwapsLnSendFailed": "Swap Failed.",
131+
"@coreSwapsLnSendFailed": {
132+
"description": "Status message for failed Lightning send swap"
133+
},
134+
"coreSwapsChainPending": "Transfer is not yet initialized.",
135+
"@coreSwapsChainPending": {
136+
"description": "Status message for pending chain swap"
137+
},
138+
"coreSwapsChainPaid": "Waiting for transfer provider's payment to receive confirmation. This may take a while to complete.",
139+
"@coreSwapsChainPaid": {
140+
"description": "Status message for paid chain swap"
141+
},
142+
"coreSwapsChainClaimable": "Transfer is ready to be claimed.",
143+
"@coreSwapsChainClaimable": {
144+
"description": "Status message for claimable chain swap"
145+
},
146+
"coreSwapsChainRefundable": "Transfer is ready to be refunded.",
147+
"@coreSwapsChainRefundable": {
148+
"description": "Status message for refundable chain swap"
149+
},
150+
"coreSwapsChainCanCoop": "Transfer will complete momentarily.",
151+
"@coreSwapsChainCanCoop": {
152+
"description": "Status message for chain swap that can complete cooperatively"
153+
},
154+
"coreSwapsChainCompletedRefunded": "Transfer has been refunded.",
155+
"@coreSwapsChainCompletedRefunded": {
156+
"description": "Status message for chain swap completed via refund"
157+
},
158+
"coreSwapsChainCompletedSuccess": "Transfer is completed successfully.",
159+
"@coreSwapsChainCompletedSuccess": {
160+
"description": "Status message for successfully completed chain swap"
161+
},
162+
"coreSwapsChainExpired": "Transfer Expired",
163+
"@coreSwapsChainExpired": {
164+
"description": "Status message for expired chain swap"
165+
},
166+
"coreSwapsChainFailedRefunding": "Transfer will be refunded shortly.",
167+
"@coreSwapsChainFailedRefunding": {
168+
"description": "Status message for failed chain swap that will be refunded"
169+
},
170+
"coreSwapsChainFailed": "Transfer Failed.",
171+
"@coreSwapsChainFailed": {
172+
"description": "Status message for failed chain swap"
173+
},
174+
"coreWalletTransactionStatusPending": "Pending",
175+
"@coreWalletTransactionStatusPending": {
176+
"description": "Display name for pending wallet transaction status"
177+
},
178+
"coreWalletTransactionStatusConfirmed": "Confirmed",
179+
"@coreWalletTransactionStatusConfirmed": {
180+
"description": "Display name for confirmed wallet transaction status"
181+
},
30182
"onboardingScreenTitle": "Welcome",
31183
"@onboardingScreenTitle": {
32184
"description": "The title of the onboarding screen"

0 commit comments

Comments
 (0)