From ff8e488dd686f9eded677aaa4cf0c2b84e5eb21c Mon Sep 17 00:00:00 2001 From: shawn Date: Wed, 9 Feb 2022 16:29:26 +0800 Subject: [PATCH] swap history data parsing fix --- CHANGELOG.md | 5 +++ lib/api/types/txSwapData.dart | 65 +++++++++++++++++++++--------- lib/pages/swap/swapDetailPage.dart | 29 ++++++------- lib/utils/i18n/zh/acala.dart | 2 +- pubspec.yaml | 6 +-- 5 files changed, 66 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d0045ec..75d39396 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [0.4.1] - 20220209 +- bump polkawallet_sdk v0.4.1. +- merge update from karura. +- lcDOT currencyId fix. + ## [0.4.0] - 20220104 - update homa module. - ui v3 update. diff --git a/lib/api/types/txSwapData.dart b/lib/api/types/txSwapData.dart index 92a971aa..0677227f 100644 --- a/lib/api/types/txSwapData.dart +++ b/lib/api/types/txSwapData.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:polkawallet_plugin_acala/polkawallet_plugin_acala.dart'; import 'package:polkawallet_plugin_acala/utils/assets.dart'; +import 'package:polkawallet_ui/utils/format.dart'; class TxSwapData extends _TxSwapData { static TxSwapData fromJson(Map json, PluginAcala plugin) { @@ -12,33 +13,57 @@ class TxSwapData extends _TxSwapData { switch (data.action) { case "swap": final List path = jsonDecode(json['data'][1]['value']); - data.tokenPay = - AssetsUtils.tokenDataFromCurrencyId(plugin, path[0])!.symbol; - data.tokenReceive = - AssetsUtils.tokenDataFromCurrencyId(plugin, path[path.length - 1])! - .symbol; + final tokenPay = AssetsUtils.tokenDataFromCurrencyId(plugin, path[0])!; + final tokenReceive = + AssetsUtils.tokenDataFromCurrencyId(plugin, path[path.length - 1])!; + data.tokenPay = tokenPay.symbol; + data.tokenReceive = tokenReceive.symbol; if (json['data'][2]['type'] == 'Balance') { - data.amountPay = json['data'][2]['value'].toString(); - data.amountReceive = json['data'][3]['value'].toString(); + data.amountPay = Fmt.priceFloorBigInt( + Fmt.balanceInt(json['data'][2]['value'].toString()), + tokenPay.decimals!, + lengthMax: 6); + data.amountReceive = Fmt.priceFloorBigInt( + Fmt.balanceInt(json['data'][3]['value'].toString()), + tokenReceive.decimals!, + lengthMax: 6); } else { - data.amountPay = jsonDecode(json['data'][2]['value'])[0].toString(); - data.amountReceive = - jsonDecode(json['data'][2]['value'])[path.length - 1].toString(); + data.amountPay = Fmt.priceFloorBigInt( + Fmt.balanceInt( + jsonDecode(json['data'][2]['value'])[0].toString()), + tokenPay.decimals!, + lengthMax: 6); + data.amountReceive = Fmt.priceFloorBigInt( + Fmt.balanceInt( + jsonDecode(json['data'][2]['value'])[path.length - 1] + .toString()), + tokenReceive.decimals!, + lengthMax: 6); } break; case "addProvision": case "addLiquidity": case "removeLiquidity": - data.tokenPay = AssetsUtils.tokenDataFromCurrencyId( - plugin, jsonDecode(json['data'][1]['value']))! - .symbol; - data.tokenReceive = AssetsUtils.tokenDataFromCurrencyId( - plugin, jsonDecode(json['data'][3]['value']))! - .symbol; - data.amountPay = json['data'][2]['value']; - data.amountReceive = json['data'][4]['value']; - data.amountShare = - (json['data'] as List).length > 5 ? json['data'][5]['value'] : ''; + final tokenPay = AssetsUtils.tokenDataFromCurrencyId( + plugin, jsonDecode(json['data'][1]['value']))!; + final tokenReceive = AssetsUtils.tokenDataFromCurrencyId( + plugin, jsonDecode(json['data'][3]['value']))!; + data.tokenPay = tokenPay.symbol; + data.tokenReceive = tokenReceive.symbol; + data.amountPay = Fmt.priceFloorBigInt( + Fmt.balanceInt(json['data'][2]['value'].toString()), + tokenPay.decimals!, + lengthMax: 6); + data.amountReceive = Fmt.priceFloorBigInt( + Fmt.balanceInt(json['data'][4]['value'].toString()), + tokenReceive.decimals!, + lengthMax: 6); + data.amountShare = (json['data'] as List).length > 5 + ? Fmt.priceFloorBigInt( + Fmt.balanceInt(json['data'][5]['value'].toString()), + tokenPay.decimals!, + lengthMax: 6) + : ''; break; } diff --git a/lib/pages/swap/swapDetailPage.dart b/lib/pages/swap/swapDetailPage.dart index 788a0a7d..859f93e0 100644 --- a/lib/pages/swap/swapDetailPage.dart +++ b/lib/pages/swap/swapDetailPage.dart @@ -3,7 +3,6 @@ import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:polkawallet_plugin_acala/api/types/txSwapData.dart'; import 'package:polkawallet_plugin_acala/polkawallet_plugin_acala.dart'; -import 'package:polkawallet_plugin_acala/utils/assets.dart'; import 'package:polkawallet_plugin_acala/utils/format.dart'; import 'package:polkawallet_plugin_acala/utils/i18n/index.dart'; import 'package:polkawallet_sdk/storage/keyring.dart'; @@ -23,15 +22,11 @@ class SwapDetailPage extends StatelessWidget { final Map dic = I18n.of(context)!.getDic(i18n_full_dic_acala, 'acala')!; - final TxSwapData tx = ModalRoute.of(context)!.settings.arguments as TxSwapData; + final TxSwapData tx = + ModalRoute.of(context)!.settings.arguments as TxSwapData; final token0 = PluginFmt.tokenView(tx.tokenPay); final token1 = PluginFmt.tokenView(tx.tokenReceive); - final balancePair = AssetsUtils.getBalancePairFromTokenNameId( - plugin, [tx.tokenPay, tx.tokenReceive]); final tokenLP = '$token0-$token1 LP'; - final amount0 = Fmt.balance(tx.amountPay, balancePair[0]!.decimals!); - final amount1 = Fmt.balance(tx.amountReceive, balancePair[1]!.decimals!); - final amountLP = Fmt.balance(tx.amountShare, balancePair[0]!.decimals!); final amountStyle = TextStyle(fontSize: 16, fontWeight: FontWeight.bold); @@ -54,11 +49,11 @@ class SwapDetailPage extends StatelessWidget { items.addAll([ TxDetailInfoItem( label: dic['dex.pay'], - content: Text('$amount0 $token0', style: amountStyle), + content: Text('${tx.amountPay} $token0', style: amountStyle), ), TxDetailInfoItem( label: dic['dex.receive'], - content: Text('$amount1 $token1', style: amountStyle), + content: Text('${tx.amountReceive} $token1', style: amountStyle), ) ]); break; @@ -66,8 +61,8 @@ class SwapDetailPage extends StatelessWidget { items.add(TxDetailInfoItem( label: dic['dex.pay'], content: Text( - '$amount0 $token0\n' - '+ $amount1 $token1', + '${tx.amountPay} $token0\n' + '+ ${tx.amountReceive} $token1', style: amountStyle, textAlign: TextAlign.right, ))); @@ -77,14 +72,14 @@ class SwapDetailPage extends StatelessWidget { TxDetailInfoItem( label: dic['dex.pay'], content: Text( - '$amount0 $token0\n' - '+ $amount1 $token1', + '${tx.amountPay} $token0\n' + '+ ${tx.amountReceive} $token1', textAlign: TextAlign.right, style: amountStyle), ), TxDetailInfoItem( label: dic['dex.receive'], - content: Text('$amountLP $tokenLP', style: amountStyle), + content: Text('${tx.amountShare} $tokenLP', style: amountStyle), ) ]); break; @@ -92,13 +87,13 @@ class SwapDetailPage extends StatelessWidget { items.addAll([ TxDetailInfoItem( label: dic['dex.pay'], - content: Text('$amountLP $tokenLP', style: amountStyle), + content: Text('${tx.amountShare} $tokenLP', style: amountStyle), ), TxDetailInfoItem( label: dic['dex.receive'], content: Text( - '$amount0 $token0\n' - '+ $amount1 $token1', + '${tx.amountPay} $token0\n' + '+ ${tx.amountReceive} $token1', textAlign: TextAlign.right, style: amountStyle), ) diff --git a/lib/utils/i18n/zh/acala.dart b/lib/utils/i18n/zh/acala.dart index 08b65ecb..c9ddd104 100644 --- a/lib/utils/i18n/zh/acala.dart +++ b/lib/utils/i18n/zh/acala.dart @@ -194,7 +194,7 @@ const Map zhDex = { 'cross.warn.info': '不建议修改跨链转账的收款地址。\n该功能仅限高级用户使用。', 'transfer.exist': '存活余额', 'transfer.fee': '预估手续费', - 'warn.fee': '因 KAR 余额不足,交易可能会执行失败。', + 'warn.fee': '因 ACA 余额不足,交易可能会执行失败。', 'v3.switchDefi': '切换至Defi', 'v3.switchBack': '切换回来', 'v3.totalBalance': '总资产', diff --git a/pubspec.yaml b/pubspec.yaml index 965fa7f1..e977b43a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: polkawallet_plugin_acala description: Acala network plugin for Polkawallet. -version: 0.3.8 +version: 0.4.1 homepage: environment: @@ -21,8 +21,8 @@ dependencies: device_info: ^2.0.1 graphql_flutter: ^5.0.0-nullsafety.5 liquid_progress_indicator: ^0.4.0 - polkawallet_sdk: ^0.3.7 - polkawallet_ui: ^0.3.6 + polkawallet_sdk: ^0.4.1 + polkawallet_ui: ^0.4.1 flutter_screenutil: ^5.0.0+2 skeleton_loader: ^2.0.0+4 rive: ^0.7.33