Skip to content

Fix leading zero amount in Buy order #1090

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

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
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
18 changes: 15 additions & 3 deletions app/lib/services/stellar_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ const String usdcAssetIssuer =
'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN';
const horizonUrl = 'https://horizon.stellar.org';

/// Formats decimal values to ensure they have a leading zero if they start with a decimal point
/// This is required by the stellar client which doesn't accept values like ".5" but needs "0.5"
String formatDecimalValue(String value) {
final trimmedValue = value.trim();
if (trimmedValue.startsWith('.')) {
return '0$trimmedValue';
}
return trimmedValue;
}

bool isValidStellarSecret(String seed) {
try {
StrKey.decodeStellarSecretSeed(seed);
Expand Down Expand Up @@ -293,8 +303,8 @@ Future<bool> createOrder(String secret, String sellingAssetCode,
return await client.createOrder(
sellingAssetCode: sellingAssetCode,
buyingAssetCode: buyingAssetCode,
amount: amount,
price: price);
amount: formatDecimalValue(amount),
price: formatDecimalValue(price));
}

Future<bool> cancelOrder(String secret, String offerID) async {
Expand All @@ -306,7 +316,9 @@ Future<bool> updateOrder(
String secret, String amount, String price, String offerID) async {
final client = Client(NetworkType.PUBLIC, secret);
return await client.updateOrder(
amount: amount, price: price, offerId: offerID);
amount: formatDecimalValue(amount),
price: formatDecimalValue(price),
offerId: offerID);
}

// The provided offer won't be counted from available balance
Expand Down