From 5d29243028f88bbfe8f46ddf2ad90fc80fcfc446 Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Tue, 3 Jun 2025 16:31:44 +0300 Subject: [PATCH] Add formatDecimalValue and use it in create/update order --- app/lib/services/stellar_service.dart | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/lib/services/stellar_service.dart b/app/lib/services/stellar_service.dart index 8bc07ba2..e74ba23a 100644 --- a/app/lib/services/stellar_service.dart +++ b/app/lib/services/stellar_service.dart @@ -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); @@ -293,8 +303,8 @@ Future createOrder(String secret, String sellingAssetCode, return await client.createOrder( sellingAssetCode: sellingAssetCode, buyingAssetCode: buyingAssetCode, - amount: amount, - price: price); + amount: formatDecimalValue(amount), + price: formatDecimalValue(price)); } Future cancelOrder(String secret, String offerID) async { @@ -306,7 +316,9 @@ Future 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