Skip to content

Commit

Permalink
swap history data parsing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
RomeroYang committed Feb 9, 2022
1 parent 8d2a157 commit ff8e488
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 41 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
65 changes: 45 additions & 20 deletions lib/api/types/txSwapData.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down
29 changes: 12 additions & 17 deletions lib/pages/swap/swapDetailPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -23,15 +22,11 @@ class SwapDetailPage extends StatelessWidget {
final Map<String, String> 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);

Expand All @@ -54,20 +49,20 @@ 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;
case "addProvision":
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,
)));
Expand All @@ -77,28 +72,28 @@ 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;
case "removeLiquidity":
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),
)
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/i18n/zh/acala.dart
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ const Map<String, String> zhDex = {
'cross.warn.info': '不建议修改跨链转账的收款地址。\n该功能仅限高级用户使用。',
'transfer.exist': '存活余额',
'transfer.fee': '预估手续费',
'warn.fee': '因 KAR 余额不足,交易可能会执行失败。',
'warn.fee': '因 ACA 余额不足,交易可能会执行失败。',
'v3.switchDefi': '切换至Defi',
'v3.switchBack': '切换回来',
'v3.totalBalance': '总资产',
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: polkawallet_plugin_acala
description: Acala network plugin for Polkawallet.
version: 0.3.8
version: 0.4.1
homepage:

environment:
Expand All @@ -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
Expand Down

0 comments on commit ff8e488

Please sign in to comment.