-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add stellar recovery service (#1549)
Co-authored-by: Kirill Bubochkin <[email protected]>
- Loading branch information
1 parent
7c8cd92
commit 1775d7d
Showing
12 changed files
with
694 additions
and
4 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/espressocash_app/lib/features/stellar_recovery/models/recovery_state.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
import '../../currency/models/amount.dart'; | ||
|
||
part 'recovery_state.freezed.dart'; | ||
|
||
@Freezed(map: FreezedMapOptions.none, when: FreezedWhenOptions.none) | ||
sealed class StellarRecoveryState with _$StellarRecoveryState { | ||
const factory StellarRecoveryState.none() = RecoveryNone; | ||
|
||
const factory StellarRecoveryState.pending({ | ||
required CryptoAmount amount, | ||
}) = RecoveryPending; | ||
|
||
const factory StellarRecoveryState.processing({ | ||
CryptoAmount? amount, | ||
String? txId, | ||
}) = RecoveryProcessing; | ||
|
||
const factory StellarRecoveryState.completed({ | ||
required CryptoAmount amount, | ||
required String txId, | ||
}) = RecoveryCompleted; | ||
|
||
const factory StellarRecoveryState.failed() = RecoveryFailed; | ||
|
||
const factory StellarRecoveryState.dismissed() = RecoveryDismissed; | ||
} | ||
|
||
extension StellarRecoveryStateX on StellarRecoveryState { | ||
CryptoAmount? get amount => switch (this) { | ||
RecoveryPending(:final amount) => amount, | ||
RecoveryProcessing(:final amount) => amount, | ||
RecoveryCompleted(:final amount) => amount, | ||
_ => null, | ||
}; | ||
} |
111 changes: 111 additions & 0 deletions
111
packages/espressocash_app/lib/features/stellar_recovery/screens/recover_stellar_screen.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../../../di.dart'; | ||
import '../../../gen/assets.gen.dart'; | ||
import '../../../l10n/device_locale.dart'; | ||
import '../../../l10n/l10n.dart'; | ||
import '../../../ui/app_bar.dart'; | ||
import '../../../ui/button.dart'; | ||
import '../../../ui/colors.dart'; | ||
import '../../conversion_rates/widgets/extensions.dart'; | ||
import '../models/recovery_state.dart'; | ||
import '../service/recovery_service.dart'; | ||
|
||
class RecoverStellarScreen extends StatelessWidget { | ||
const RecoverStellarScreen({super.key, required this.onConfirmed}); | ||
|
||
final VoidCallback onConfirmed; | ||
|
||
static void push( | ||
BuildContext context, { | ||
required VoidCallback onConfirmed, | ||
}) => | ||
Navigator.of(context).push<void>( | ||
MaterialPageRoute( | ||
builder: (context) => RecoverStellarScreen( | ||
onConfirmed: onConfirmed, | ||
), | ||
), | ||
); | ||
|
||
void _handleRecoverPressed() { | ||
sl<StellarRecoveryService>().recover(); | ||
onConfirmed(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) => Scaffold( | ||
backgroundColor: CpColors.yellowSplashBackgroundColor, | ||
appBar: CpAppBar( | ||
scrolledUnderColor: CpColors.yellowSplashBackgroundColor, | ||
title: Text(context.l10n.moneyRecoveryTitle), | ||
), | ||
extendBodyBehindAppBar: true, | ||
extendBody: true, | ||
bottomNavigationBar: SafeArea( | ||
child: Padding( | ||
padding: const EdgeInsets.all(32), | ||
child: CpButton( | ||
onPressed: _handleRecoverPressed, | ||
text: context.l10n.moneyRecoveryBtn, | ||
), | ||
), | ||
), | ||
body: Stack( | ||
children: [ | ||
Align( | ||
child: Assets.images.dollarBg.image( | ||
fit: BoxFit.fitHeight, | ||
height: double.infinity, | ||
), | ||
), | ||
Padding( | ||
padding: const EdgeInsets.symmetric(horizontal: 24), | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
Assets.icons.money.svg( | ||
height: 90, | ||
width: 90, | ||
), | ||
const SizedBox(height: 24), | ||
Text( | ||
context.l10n.moneyRecoveryContent( | ||
sl<StellarRecoveryService>() | ||
.value | ||
.amount | ||
?.format(context.locale, maxDecimals: 2) ?? | ||
'-', | ||
), | ||
textAlign: TextAlign.center, | ||
style: const TextStyle( | ||
fontWeight: FontWeight.w600, | ||
fontSize: 32, | ||
height: 0.95, | ||
), | ||
), | ||
const SizedBox(height: 12), | ||
Text( | ||
context.l10n.moneyRecoverySubContent, | ||
textAlign: TextAlign.center, | ||
style: const TextStyle( | ||
fontWeight: FontWeight.w500, | ||
fontSize: 18, | ||
), | ||
), | ||
const SizedBox(height: 6), | ||
Text( | ||
context.l10n.moneyRecoveryDisclaimer, | ||
textAlign: TextAlign.center, | ||
style: const TextStyle( | ||
fontWeight: FontWeight.w400, | ||
fontSize: 14, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} |
Oops, something went wrong.