Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update ata closed authority #1528

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,6 @@ class AnalyticsManager {
'id': id,
},
);

void ataCreated() => _analytics.track('ataCreated');
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:solana/solana.dart';

import '../../utils/transactions.dart';
import '../accounts/models/ec_wallet.dart';
import '../analytics/analytics_manager.dart';
import '../priority_fees/services/add_priority_fees.dart';
import '../tokens/token.dart';
import '../transactions/services/resign_tx.dart';
Expand All @@ -18,11 +19,13 @@ class CreateIncomingEscrow {
this._client,
this._addPriorityFees,
this._ecClient,
this._analyticsManager,
);

final SolanaClient _client;
final AddPriorityFees _addPriorityFees;
final EspressoCashClient _ecClient;
final AnalyticsManager _analyticsManager;

Future<SignedTx> call({
required Ed25519HDKeyPair escrowAccount,
Expand Down Expand Up @@ -67,7 +70,18 @@ class CreateIncomingEscrow {
mint: mint,
);

instructions.add(iCreateATA);
final newAuthorityIx = TokenInstruction.setAuthority(
mintOrAccount: ataReceiver,
authorityType: AuthorityType.closeAccount,
currentAuthority: ataReceiver,
newAuthority: platformAccount,
);

instructions
..add(iCreateATA)
..add(newAuthorityIx);

_analyticsManager.ataCreated();
}

final escrowIx = await EscrowInstruction.completeEscrow(
Expand All @@ -79,25 +93,6 @@ class CreateIncomingEscrow {

instructions.add(escrowIx);

final int fee;
if (shouldCreateAta) {
final transactionFees = await _ecClient.getFees();
fee = transactionFees.escrowPaymentAtaFee;
final ataPlatform = await findAssociatedTokenAddress(
owner: platformAccount,
mint: mint,
);
final iTransferFee = TokenInstruction.transfer(
amount: fee,
source: ataReceiver,
destination: ataPlatform,
owner: receiverAccount,
);
instructions.add(iTransferFee);
} else {
fee = 0;
}

final message = Message(
instructions: [
SystemInstruction.advanceNonceAccount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import 'package:solana/encoder.dart';
import '../../../data/db/db.dart';
import '../../../data/db/mixins.dart';
import '../../accounts/auth_scope.dart';
import '../../currency/models/amount.dart';
import '../../currency/models/currency.dart';
import '../../escrow/models/escrow_private_key.dart';
import '../../transactions/models/tx_results.dart';
import '../models/incoming_link_payment.dart';
Expand Down Expand Up @@ -104,13 +102,8 @@ extension on ILPStatusDto {
signature: row.txId!,
);
case ILPStatusDto.success:
final feeAmount = row.feeAmount;

return ILPStatus.success(
tx: tx ?? StubSignedTx(txId!),
fee: feeAmount != null
? CryptoAmount(value: feeAmount, cryptoCurrency: Currency.usdc)
: null,
);
case ILPStatusDto.txFailure:
return ILPStatus.txFailure(
Expand All @@ -129,10 +122,6 @@ extension on IncomingLinkPayment {
tx: status.toTx(),
txId: status.toTxId(),
txFailureReason: status.toTxFailureReason(),
feeAmount: switch (status) {
ILPStatusSuccess(:final fee) => fee?.value,
_ => null,
},
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:solana/encoder.dart';

import '../../currency/models/amount.dart';
import '../../escrow/models/escrow_private_key.dart';
import '../../transactions/models/tx_results.dart';

Expand Down Expand Up @@ -31,7 +30,6 @@ sealed class ILPStatus with _$ILPStatus {
/// Final state. Tx is successfully confirmed and payment is claimed.
const factory ILPStatus.success({
required SignedTx tx,
required CryptoAmount? fee,
}) = ILPStatusSuccess;

/// Failed to create the tx, a new tx should be created.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import 'package:dfunc/dfunc.dart';
import 'package:flutter/material.dart';

import '../../../di.dart';
import '../../../l10n/device_locale.dart';
import '../../../l10n/l10n.dart';
import '../../../ui/colors.dart';
import '../../../ui/info_icon.dart';
import '../../../ui/message_info_widget.dart';
import '../../conversion_rates/widgets/extensions.dart';
import '../../currency/models/amount.dart';
import '../../transactions/models/tx_results.dart';
import '../../transactions/widgets/transfer_error.dart';
import '../../transactions/widgets/transfer_progress.dart';
Expand Down Expand Up @@ -60,7 +53,6 @@ class _IncomingLinkPaymentScreenState extends State<IncomingLinkPaymentScreen> {
success: (e) => TransferSuccess(
onBack: () => Navigator.pop(context),
onOkPressed: () => Navigator.pop(context),
content: e.fee?.let(_FeeNotice.new),
statusContent: context.l10n.moneyReceived,
),
txFailure: (it) => it.reason == TxFailureReason.escrowFailure
Expand All @@ -75,47 +67,3 @@ class _IncomingLinkPaymentScreenState extends State<IncomingLinkPaymentScreen> {
},
);
}

class _FeeNotice extends StatelessWidget {
const _FeeNotice(this.amount);

final CryptoAmount amount;

@override
Widget build(BuildContext context) => Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
CpMessageInfoWidget(
backgroundColor: Colors.black,
padding: const EdgeInsets.all(18),
content: Row(
children: [
const CircleAvatar(
maxRadius: 14,
backgroundColor: CpColors.yellowColor,
child: CpInfoIcon(
iconColor: CpColors.darkBackgroundColor,
),
),
const SizedBox(width: 16),
Expanded(
child: Text(
context.l10n
.incomingUsdcFeeNotice(amount.format(context.locale)),
style: const TextStyle(
color: Colors.white,
fontSize: 14.50,
fontWeight: FontWeight.w500,
height: 0,
),
),
),
],
),
),
const SizedBox(height: 32),
],
),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ import 'package:espressocash_api/espressocash_api.dart';
import 'package:get_it/get_it.dart';
import 'package:injectable/injectable.dart';
import 'package:rxdart/rxdart.dart';
import 'package:solana/encoder.dart';
import 'package:solana/solana.dart';
import 'package:uuid/uuid.dart';

import '../../accounts/auth_scope.dart';
import '../../accounts/models/ec_wallet.dart';
import '../../balances/services/refresh_balance.dart';
import '../../currency/models/amount.dart';
import '../../currency/models/currency.dart';
import '../../escrow/models/escrow_private_key.dart';
import '../../escrow_payments/create_incoming_escrow.dart';
import '../../escrow_payments/escrow_exception.dart';
Expand Down Expand Up @@ -147,23 +144,11 @@ class ILPService implements Disposable {

await _txConfirm(txId: status.signature);

int? fee;
try {
fee = status.tx.containsAta
? await _ecClient.getFees().then((value) => value.escrowPaymentAtaFee)
: null;
} on Object {
fee = null;
}

_refreshBalance();

return payment.copyWith(
status: ILPStatus.success(
tx: status.tx,
fee: fee?.let(
(fee) => CryptoAmount(value: fee, cryptoCurrency: Currency.usdc),
),
),
);
}
Expand All @@ -173,10 +158,3 @@ class ILPService implements Disposable {
await Future.wait(_subscriptions.values.map((it) => it.cancel()));
}
}

extension on SignedTx {
bool get containsAta => decompileMessage().let(
(m) => m.instructions
.any((ix) => ix.programId == AssociatedTokenAccountProgram.id),
);
}
2 changes: 0 additions & 2 deletions packages/espressocash_app/lib/l10n/intl_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@
"@help": {},
"incomingSplitKeyPayments_lblByClickingTheSecondLink": "Al hacer clic en el segundo enlace del mensaje o en el botón de cancelación, aceptas nuestra ",
"@incomingSplitKeyPayments_lblByClickingTheSecondLink": {},
"incomingUsdcFeeNotice": "Se te ha cobrado una tarifa única de $0.10 por tu primera transacción entrante.",
"@incomingUsdcFeeNotice": {},
"incorrectPasscode": "código de acceso incorrecto.Volver a intentarlo",
"@incorrectPasscode": {},
"insufficientFundsForFeeMessage": "No tienes suficiente {feeToken} para pagar la tarifa de la red, necesita al menos {amount}.",
Expand Down
2 changes: 0 additions & 2 deletions packages/espressocash_app/lib/l10n/intl_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@
"@help": {},
"incomingSplitKeyPayments_lblByClickingTheSecondLink": "En cliquant sur le deuxième lien du message ou sur le bouton d'annulation, vous acceptez nos ",
"@incomingSplitKeyPayments_lblByClickingTheSecondLink": {},
"incomingUsdcFeeNotice": "Un frais unique de {amount} a été prélevé pour votre première transaction entrante.",
"@incomingUsdcFeeNotice": {},
"incorrectPasscode": "Code d'accès incorrect. Réessayer à nouveau",
"@incorrectPasscode": {},
"insufficientFundsForFeeMessage": "Vous n'avez pas assez {feeToken} pour payer les frais de réseau, vous avez besoin d'au moins {amount}.",
Expand Down
2 changes: 0 additions & 2 deletions packages/espressocash_app/lib/l10n/intl_ru.arb
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@
"@help": {},
"incomingSplitKeyPayments_lblByClickingTheSecondLink": "Нажав на вторую ссылку в сообщении или кнопку \"Отмена\", вы соглашаетесь с нашими",
"@incomingSplitKeyPayments_lblByClickingTheSecondLink": {},
"incomingUsdcFeeNotice": "С вас была снята единовременная комиссия в размере {amount} за вашу первую входящую транзакцию.",
"@incomingUsdcFeeNotice": {},
"incorrectPasscode": "Неверный пин-код. Попробуйте еще раз.",
"@incorrectPasscode": {},
"insufficientFundsForFeeMessage": "У вас недостаточно {feeToken} для оплаты комиссии сети, вам нужно как минимум {amount}.",
Expand Down
3 changes: 3 additions & 0 deletions packages/espressocash_app/test/stub_analytics_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,7 @@ class StubAnalyticsManager implements AnalyticsManager {

@override
void rampOpened({required RampPartner partner, required String rampType}) {}

@override
void ataCreated() {}
}
Loading