Skip to content

Commit

Permalink
feat: add stellar recovery service (#1549)
Browse files Browse the repository at this point in the history
Co-authored-by: Kirill Bubochkin <[email protected]>
  • Loading branch information
justinenerio and ookami-kb committed Sep 2, 2024
1 parent 7c8cd92 commit 1775d7d
Show file tree
Hide file tree
Showing 12 changed files with 694 additions and 4 deletions.
12 changes: 12 additions & 0 deletions packages/espressocash_app/assets/icons/money.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ class AccessMode with _$AccessMode {
const factory AccessMode.seedInputted() = _SeedInputted;
const factory AccessMode.created() = _AccountCreated;
}

extension AccessModeExt on AccessMode {
bool get isLoaded => this is _Loaded;
bool get isSeedInputted => this is _SeedInputted;
bool get isAccountCreated => this is _AccountCreated;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import '../../../l10n/l10n.dart';
import '../../../ui/button.dart';
import '../../../ui/colors.dart';
import '../../../ui/info_icon.dart';
import '../../stellar_recovery/widgets/stellar_recovery_notice.dart';
import 'balance_amount.dart';

class InvestmentHeader extends StatefulWidget {
Expand Down Expand Up @@ -33,6 +34,7 @@ class _InvestmentHeaderState extends State<InvestmentHeader> {
const SizedBox(height: 4),
const BalanceAmount(),
const SizedBox(height: 12),
const StellarRecoveryNotice(),
],
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class IntercomService implements Disposable {
void updateCountry(String? countryCode) => Intercom.instance
.updateUser(customAttributes: {'countryCode': countryCode});

void updateStellarAddress(String address) => Intercom.instance.updateUser(
customAttributes: {'stellarAddress': address},
);

@override
Future<void> onDispose() => Intercom.instance.logout();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ import 'package:sentry_flutter/sentry_flutter.dart';

import '../../accounts/auth_scope.dart';
import '../../analytics/analytics_manager.dart';
import '../../intercom/services/intercom_service.dart';
import '../models/stellar_wallet.dart';

@Singleton(scope: authScope)
class StellarAccountService {
const StellarAccountService(this._stellarWallet, this._analyticsManager);
const StellarAccountService(
this._stellarWallet,
this._analyticsManager,
this._intercomService,
);

final StellarWallet _stellarWallet;
final AnalyticsManager _analyticsManager;
final IntercomService _intercomService;

@postConstruct
void init() {
Expand All @@ -20,6 +26,7 @@ class StellarAccountService {
(scope) => scope.setExtra('stellarWalletAddress', address),
);
_analyticsManager.setStellarAddress(address);
_intercomService.updateStellarAddress(address);
}

@disposeMethod
Expand Down
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,
};
}
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,
),
),
],
),
),
],
),
);
}
Loading

0 comments on commit 1775d7d

Please sign in to comment.