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

fix: stellar recovery #1570

Merged
merged 7 commits into from
Sep 13, 2024
Merged
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 @@ -6,7 +6,7 @@ enum RampPartner {
coinflow(title: 'Coinflow', minimumAmount: r'$20'),
guardarian(title: 'Guardarian', minimumAmount: r'$5'),
scalex(title: 'Scalex', minimumAmount: r'$5'),
moneygram(title: 'MoneyGram', minimumAmount: r'$5');
moneygram(title: 'MoneyGram', minimumAmount: r'$10');

const RampPartner({required this.title, required this.minimumAmount});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,19 @@ class StellarRecoveryService extends ValueNotifier<StellarRecoveryState> {
return;
}

final amount = Amount.fromDecimal(
final walletAmount = Amount.fromDecimal(
value: Decimal.parse(usdcBalance.toString()),
currency: Currency.usdc,
) as CryptoAmount;

final hash = await _initiateSwapToSolana(amount);
final hash = await _initiateSwapToSolana(walletAmount);

final receivedAmount =
_storage.getInt(_stellarRecoveryAmountKey).toCryptoAmount;

value =
StellarRecoveryState.processing(amount: receivedAmount, txId: hash);

value = StellarRecoveryState.processing(amount: value.amount, txId: hash);
_watchBridgeTx();
} on Exception {
value = const StellarRecoveryState.failed();
Expand Down Expand Up @@ -164,17 +169,23 @@ class StellarRecoveryService extends ValueNotifier<StellarRecoveryState> {
}

void _watchBridgeTx() {
_watcher =
Stream<void>.periodic(const Duration(seconds: 15)).listen((_) async {
final txId = switch (value) {
RecoveryProcessing(:final txId) => txId,
_ => null,
};
final txId = switch (value) {
RecoveryProcessing(:final txId) => txId,
_ => null,
};

if (txId == null) {
return;
}
if (txId == null || txId.isEmpty) {
_watcher?.cancel();

value = StellarRecoveryState.pending(
amount: _storage.getInt(_stellarRecoveryAmountKey).toCryptoAmount,
);

return;
}

_watcher =
Stream<void>.periodic(const Duration(seconds: 5)).listen((_) async {
final response = await _allbridgeApiClient.fetchStatus(
chain: Chain.stellar,
hash: txId,
Expand Down
Loading