Skip to content

Commit

Permalink
Merge branch 'master' into feat/store-token-list-localdb
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaxiii committed Aug 15, 2024
2 parents 6e60d45 + 3d74bdc commit dd363aa
Show file tree
Hide file tree
Showing 29 changed files with 1,754 additions and 170 deletions.
8 changes: 6 additions & 2 deletions packages/espressocash_app/lib/data/db/db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class OutgoingTransferRows extends Table {
Set<Column<Object>> get primaryKey => {id};
}

const int latestVersion = 55;
const int latestVersion = 56;

const _tables = [
OutgoingTransferRows,
Expand Down Expand Up @@ -151,7 +151,10 @@ class MyDatabase extends _$MyDatabase {
offRampOrderRows.referenceNumber,
);
}
if (from < 55) {
if (from >= 40 && from < 55) {
await m.addColumn(offRampOrderRows, offRampOrderRows.refundAmount);
}
if (from < 56) {
await m.createTable(tokenRows);
}
},
Expand Down Expand Up @@ -212,6 +215,7 @@ class OffRampOrderRows extends Table with AmountMixin, EntityMixin {
TextColumn get stellarTxHash => text().nullable()();
IntColumn get bridgeAmount => integer().nullable()();
TextColumn get referenceNumber => text().nullable()();
IntColumn get refundAmount => integer().nullable()();
}

enum OnRampOrderStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class AnalyticsManager {
}
}

void setStellarAddress(String? address) {
_analytics.getPeople().set('stellarWalletAddress', address);
}

void setUsdcBalance(Decimal value) {
_analytics.getPeople().set('usdcBalance', value.toDouble());
}
Expand Down Expand Up @@ -68,4 +72,20 @@ class AnalyticsManager {
'directPaymentSent',
properties: {'amount': amount.toDouble()},
);

void paymentRequestLinkCreated({
required Decimal amount,
}) =>
_analytics.track(
'paymentRequestLinkCreated',
properties: {'amount': amount.toDouble()},
);

void paymentRequestLinkPaid({
required Decimal amount,
}) =>
_analytics.track(
'paymentRequestLinkPaid',
properties: {'amount': amount.toDouble()},
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import '../../transactions/widgets/transfer_progress.dart';
import '../../transactions/widgets/transfer_success.dart';
import '../data/ilp_repository.dart';
import '../models/incoming_link_payment.dart';
import '../widgets/extensions.dart';
import '../widgets/invalid_escrow_error_widget.dart';

class IncomingLinkPaymentScreen extends StatefulWidget {
Expand Down Expand Up @@ -68,7 +67,6 @@ class _IncomingLinkPaymentScreenState extends State<IncomingLinkPaymentScreen> {
? const InvalidEscrowErrorWidget()
: TransferError(
onBack: () => Navigator.pop(context),
onRetry: () => context.retryILP(payment),
),
orElse: () => TransferProgress(
onBack: () => Navigator.pop(context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,6 @@ class ILPService implements Disposable {
return payment;
}

Future<IncomingLinkPayment> retry(
IncomingLinkPayment payment, {
required ECWallet account,
}) async {
final status = await _createTx(
escrow: await payment.escrow.keyPair,
account: account,
);

final newPayment = payment.copyWith(status: status);

await _repository.save(newPayment);
_subscribe(payment.id);

return newPayment;
}

Future<ILPStatus> _createTx({
required ECWallet account,
required Ed25519HDKeyPair escrow,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:solana/solana.dart';
import '../../../di.dart';
import '../../../ui/loader.dart';
import '../../accounts/models/account.dart';
import '../models/incoming_link_payment.dart';
import '../services/ilp_service.dart';

extension BuildContextExt on BuildContext {
Expand All @@ -23,17 +22,6 @@ extension BuildContextExt on BuildContext {

return payment.id;
});

Future<void> retryILP(IncomingLinkPayment payment) =>
runWithLoader(this, () async {
final span = _start(function: 'retryILP');

await sl<ILPService>().retry(
payment,
account: sl<MyAccount>().wallet,
);
await span.finish();
});
}

ISentrySpan _start({required String function}) => Sentry.startTransaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class _ODPDetailsScreenState extends State<ODPDetailsScreen> {
),
txFailure: (it) => TransferError(
onBack: () => Navigator.pop(context),
onRetry: () => context.retryODP(paymentId: payment.id),
onCancel: () => _handleCancel(payment.id),
reason: it.reason,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,6 @@ class ODPService {
return payment;
}

Future<void> retry(
String paymentId, {
required ECWallet account,
}) async {
final payment = await _repository.load(paymentId);
if (payment == null || !payment.isRetriable) return;

final status = await _createTx(
account: account,
receiver: payment.receiver,
amount: payment.amount,
reference: payment.reference,
);

final newPayment = payment.copyWith(status: status);

await _repository.save(newPayment);
_subscribe(newPayment.id);
}

Future<void> cancel(String paymentId) async {
final payment = await _repository.load(paymentId);
if (payment == null || !payment.isRetriable) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ extension BuildContextExt on BuildContext {
return payment.id;
});

Future<void> retryODP({required String paymentId}) =>
runWithLoader(this, () async {
await sl<ODPService>().retry(
paymentId,
account: sl<MyAccount>().wallet,
);
});

Future<void> cancelODP({required String paymentId}) =>
runWithLoader(this, () async {
await sl<ODPService>().cancel(paymentId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,6 @@ class _OLPScreenState extends State<OLPScreen> {
cancelButton,
],
txFailure: (s) => [
CpButton(
size: CpButtonSize.big,
width: double.infinity,
text: context.l10n.retry,
onPressed: () => context.retryOLP(payment: payment),
),
cancelButton,
],
cancelTxFailure: (s) => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,6 @@ class OLPService implements Disposable {
return payment;
}

Future<OutgoingLinkPayment> retry(
OutgoingLinkPayment payment, {
required ECWallet account,
}) async {
final status = await _createTx(
amount: payment.amount,
account: account,
);

final newPayment = payment.copyWith(status: status);

await _repository.save(newPayment);
_subscribe(payment.id);

return newPayment;
}

Future<OutgoingLinkPayment> cancel(
OutgoingLinkPayment payment, {
required ECWallet account,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ extension BuildContextExt on BuildContext {
);
await span.finish();
});

Future<void> retryOLP({required OutgoingLinkPayment payment}) =>
runWithLoader<void>(this, () async {
final span = _start(function: 'retryOLP');
await sl<OLPService>().retry(
payment,
account: sl<MyAccount>().wallet,
);
await span.finish();
});
}

ISentrySpan _start({required String function}) => Sentry.startTransaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:solana/solana_pay.dart';
import 'package:uuid/uuid.dart';

import '../../accounts/auth_scope.dart';
import '../../analytics/analytics_manager.dart';
import '../../balances/services/refresh_balance.dart';
import '../../currency/models/amount.dart';
import '../../tokens/token.dart';
Expand All @@ -23,12 +24,14 @@ class PaymentRequestService implements Disposable {
PaymentRequestService(
this._repository,
this._solanaClient,
this._analyticsManager,
this._refreshBalance,
this._ecClient,
);

final PaymentRequestRepository _repository;
final SolanaClient _solanaClient;
final AnalyticsManager _analyticsManager;
final RefreshBalance _refreshBalance;
final EspressoCashClient _ecClient;

Expand Down Expand Up @@ -126,6 +129,10 @@ class PaymentRequestService implements Disposable {
),
);

_analyticsManager.paymentRequestLinkPaid(
amount: request.payRequest.amount ?? Decimal.zero,
);

_refreshBalance();

await _subscriptions[request.id]?.cancel();
Expand Down Expand Up @@ -178,6 +185,8 @@ class PaymentRequestService implements Disposable {
);
await _repository.save(paymentRequest);

_analyticsManager.paymentRequestLinkCreated(amount: amount);

_subscribe(paymentRequest);

return paymentRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,20 @@ class MoneygramOffRampOrderService implements Disposable {

final solanaAddress = _ecWallet.address;

final refundAmount = await _ecClient
.calculateMoneygramFee(
MoneygramFeeRequestDto(
type: RampTypeDto.onRamp,
amount: (int.parse(response.amount) / 10000000).toString(),
),
)
.then(
(e) => Amount.fromDecimal(
value: Decimal.parse(e.totalAmount),
currency: Currency.usdc,
),
);

final bridgeTx = await _ecClient
.swapToSolana(
SwapToSolanaRequestDto(
Expand Down Expand Up @@ -695,6 +709,7 @@ class MoneygramOffRampOrderService implements Disposable {
: OffRampOrderRowsCompanion(
stellarTxHash: Value(hash),
status: const Value(OffRampOrderStatus.waitingForRefundBridge),
refundAmount: Value(refundAmount.value),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,14 @@ class _Timeline extends StatelessWidget {

final bridgingToStellar = CpTimelineItem(
title: context.l10n.bridgingText,
trailing: order.bridgeAmount?.let(
(e) => e.isZero ? null : e.format(context.locale, maxDecimals: 2),
),
);
final amountSent = CpTimelineItem(
title: context.l10n.offRampWithdrawSent,
trailing: isMoneygramOrder
? order.bridgeAmount?.let(
(e) => e.isZero ? null : e.format(context.locale, maxDecimals: 2),
)
: null,
);
final paymentSuccess = CpTimelineItem(
title: context.l10n.offRampWithdrawReceived,
Expand All @@ -412,10 +414,18 @@ class _Timeline extends StatelessWidget {
);
final paymentCanceled = CpTimelineItem(
title: context.l10n.offRampWithdrawCancelledTitle,
trailing: isMoneygramOrder
? order.refundAmount?.let(
(e) => e.isZero ? null : e.format(context.locale, maxDecimals: 2),
)
: null,
subtitle: order.resolved?.let((t) => context.formatDate(t)),
);
const refunding = CpTimelineItem(
final refunding = CpTimelineItem(
title: 'Refunding USDC',
trailing: order.bridgeAmount?.let(
(e) => e.isZero ? null : e.format(context.locale, maxDecimals: 2),
),
);

final normalItems = [
Expand Down Expand Up @@ -549,6 +559,7 @@ extension on OffRampOrderStatus {
this == OffRampOrderStatus.waitingForRefundBridge;

bool get isWaitingForBridge =>
this == OffRampOrderStatus.preProcessing ||
this == OffRampOrderStatus.waitingForRefundBridge ||
this == OffRampOrderStatus.postProcessing;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ typedef OffRampOrder = ({
String? authToken,
String? referenceNumber,
CryptoAmount? bridgeAmount,
CryptoAmount? refundAmount,
});

@Singleton(scope: authScope)
Expand Down Expand Up @@ -154,6 +155,9 @@ class OffRampOrderService implements Disposable {
.maybeWhere((it) => it.isNotEmpty)
?.let(Ed25519HDPublicKey.fromBase58);

final refundAmount = row.refundAmount
?.let((it) => CryptoAmount(value: it, cryptoCurrency: Currency.usdc));

return (
id: row.id,
created: row.created,
Expand All @@ -171,6 +175,7 @@ class OffRampOrderService implements Disposable {
authToken: row.authToken,
referenceNumber: row.referenceNumber,
bridgeAmount: bridgeAmount,
refundAmount: refundAmount,
);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ class _MoneygramDepositContent extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Assets.gifs.moneygramConfirmationAnimation.image(),
Assets.gifs.moneygramConfirmationAnimation
.image(width: 320),
const SizedBox(height: 16),
Assets.images.moneygramLogo.image(height: 32),
const SizedBox(height: 16),
Expand Down
Loading

0 comments on commit dd363aa

Please sign in to comment.