Skip to content

Commit

Permalink
update nominating list & acala faucet api
Browse files Browse the repository at this point in the history
  • Loading branch information
RomeroYang committed Sep 25, 2020
1 parent 49f16d7 commit 493f9dd
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 56 deletions.
12 changes: 6 additions & 6 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = WQ5H736A22;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -396,7 +396,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
MARKETING_VERSION = 1.0.3;
MARKETING_VERSION = 1.0.4;
PRODUCT_BUNDLE_IDENTIFIER = io.polkawallet.polkawallet;
PRODUCT_NAME = Runner;
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down Expand Up @@ -518,7 +518,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = WQ5H736A22;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -531,7 +531,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
MARKETING_VERSION = 1.0.3;
MARKETING_VERSION = 1.0.4;
PRODUCT_BUNDLE_IDENTIFIER = io.polkawallet.polkawallet;
PRODUCT_NAME = Runner;
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand All @@ -548,7 +548,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = WQ5H736A22;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -561,7 +561,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
MARKETING_VERSION = 1.0.3;
MARKETING_VERSION = 1.0.4;
PRODUCT_BUNDLE_IDENTIFIER = io.polkawallet.polkawallet;
PRODUCT_NAME = Runner;
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down
4 changes: 2 additions & 2 deletions lib/common/consts/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ const String cross_chain_transfer_address_laminar =
'5CLaminarAUSDCrossChainTransferxxxxxxxxxxxxxwisu';

/// app versions
const String app_beta_version = 'v1.0.3-beta.3';
const int app_beta_version_code = 1033;
const String app_beta_version = 'v1.0.4-beta.1';
const int app_beta_version_code = 1041;

/// js code versions
const Map<String, int> js_code_version_map = {
Expand Down
18 changes: 8 additions & 10 deletions lib/page/assets/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,10 @@ class _AssetsState extends State<Assets> {
final String res = await webApi.acala.fetchFaucet();
String dialogContent = I18n.of(context).acala['faucet.ok'];
bool isOK = false;
if (res == null || res == "ERROR") {
dialogContent = I18n.of(context).acala['faucet.error'];
} else if (res == "LIMIT") {
dialogContent = I18n.of(context).acala['faucet.limit'];
} else {
if (res != null && res == "success") {
isOK = true;
} else {
dialogContent = res ?? I18n.of(context).acala['faucet.error'];
}

Timer(Duration(seconds: 3), () {
Expand All @@ -213,11 +211,11 @@ class _AssetsState extends State<Assets> {
Navigator.of(context).pop();
if (isOK) {
globalBalanceRefreshKey.currentState.show();
NotificationPlugin.showNotification(
int.parse(res.substring(0, 6)),
I18n.of(context).assets['notify.receive'],
'{"ACA": 2, "aUSD": 2, "DOT": 2, "XBTC": 0.2}',
);
// NotificationPlugin.showNotification(
// int.parse(res.substring(0, 6)),
// I18n.of(context).assets['notify.receive'],
// '{"ACA": 2, "aUSD": 2, "DOT": 2, "XBTC": 0.2}',
// );
}
},
),
Expand Down
106 changes: 70 additions & 36 deletions lib/page/staking/validators/overview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -278,54 +278,61 @@ class _StakingOverviewPageState extends State<StakingOverviewPage>
}

Widget _buildNominatingList() {
final dic = I18n.of(context).staking;
if (store.staking.ownStashInfo == null ||
store.staking.validatorsInfo.length == 0) {
return Container();
}

final stashId = store.staking.ownStashInfo.stashId;
final NomineesInfoData nomineesInfo = store.staking.ownStashInfo.inactives;
final List<Widget> list = nomineesInfo.nomsActive.map((e) {
int validatorIndex =
store.staking.validatorsInfo.indexWhere((i) => i.accountId == e);
final List<Widget> list = nomineesInfo.nomsActive.map((id) {
return Expanded(
child: validatorIndex < 0
? Container()
: _NomineeItem(
store.staking.validatorsInfo[validatorIndex],
true,
store.account.addressIndexMap,
),
child: _NomineeItem(
id,
store.staking.validatorsInfo,
stashId,
NomStatus.active,
store.settings.networkState.tokenDecimals,
store.account.addressIndexMap,
),
);
}).toList();

list.addAll(nomineesInfo.nomsInactive.map((e) {
final validatorIndex =
store.staking.validatorsInfo.indexWhere((i) => i.accountId == e);
final validator = validatorIndex < 0
? ValidatorData.fromJson({'accountId': e})
: store.staking.validatorsInfo[validatorIndex];
list.addAll(nomineesInfo.nomsOver.map((id) {
return Expanded(
child: _NomineeItem(
id,
store.staking.validatorsInfo,
stashId,
NomStatus.over,
store.settings.networkState.tokenDecimals,
store.account.addressIndexMap,
),
);
}).toList());

list.addAll(nomineesInfo.nomsInactive.map((id) {
return Expanded(
child: _NomineeItem(
validator,
false,
id,
store.staking.validatorsInfo,
stashId,
NomStatus.inactive,
store.settings.networkState.tokenDecimals,
store.account.addressIndexMap,
),
);
}).toList());

list.addAll(nomineesInfo.nomsWaiting.map((id) {
final validatorIndex =
store.staking.validatorsInfo.indexWhere((i) => i.accountId == id);
final validator = validatorIndex < 0
? ValidatorData.fromJson({'accountId': id})
: store.staking.validatorsInfo[validatorIndex];
return Expanded(
child: _NomineeItem(
validator,
false,
id,
store.staking.validatorsInfo,
stashId,
NomStatus.waiting,
store.settings.networkState.tokenDecimals,
store.account.addressIndexMap,
waiting: true,
),
);
}).toList());
Expand Down Expand Up @@ -504,26 +511,53 @@ class _StakingOverviewPageState extends State<StakingOverviewPage>
}
}

class _NomineeItem extends StatelessWidget {
_NomineeItem(this.validator, this.active, this.accInfoMap,
{this.waiting = false});
enum NomStatus { active, over, inactive, waiting }

final ValidatorData validator;
final bool active;
final bool waiting;
class _NomineeItem extends StatelessWidget {
_NomineeItem(
this.id,
this.validators,
this.stashId,
this.nomStatus,
this.decimals,
this.accInfoMap,
);

final String id;
final List<ValidatorData> validators;
final String stashId;
final NomStatus nomStatus;
final int decimals;
final Map<String, Map> accInfoMap;

@override
Widget build(BuildContext context) {
final dic = I18n.of(context).staking;

final validatorIndex = validators.indexWhere((i) => i.accountId == id);
final validator = validatorIndex < 0
? ValidatorData.fromJson({'accountId': id})
: validators[validatorIndex];

final accInfo = accInfoMap[validator.accountId];
final status = nomStatus.toString().split('.')[1];

BigInt meStaked;
int meIndex = validator.nominators.indexWhere((i) => i['who'] == stashId);
if (meIndex >= 0) {
meStaked =
BigInt.parse(validator.nominators[meIndex]['value'].toString());
}
String subtitle = dic['nominate.$status'];
if (nomStatus == NomStatus.active) {
subtitle += ' ${Fmt.token(meStaked ?? BigInt.zero, decimals)}';
}

return ListTile(
dense: true,
leading: AddressIcon(validator.accountId, size: 32),
title: Fmt.accountDisplayName(validator.accountId, accInfo),
subtitle: Text(waiting
? dic['nominate.waiting']
: active ? dic['nominate.active'] : dic['nominate.inactive']),
subtitle: Text(subtitle),
trailing: Container(
width: 100,
child: Column(
Expand Down
29 changes: 29 additions & 0 deletions lib/service/faucet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:http/http.dart';

class FaucetApi {
static const String _endpoint = 'https://api.polkawallet.io/faucet';
static const String _endpointV2 = 'https://api.polkawallet.io/v2/faucet';

static Future<String> getAcalaTokens(String address, String deviceId) async {
Map<String, String> headers = {"Content-type": "application/json"};
Expand All @@ -24,6 +25,34 @@ class FaucetApi {
}
}

static Future<String> getAcalaTokensV2(
String address, String deviceId) async {
Map<String, String> headers = {"Content-type": "application/json"};
String body = jsonEncode({
"address": address,
"account": deviceId,
});
try {
Response res =
await post('$_endpointV2/faucet', headers: headers, body: body);
if (res.statusCode == 200) {
try {
final body = jsonDecode(res.body);
if (body['code'] == 200) {
return 'success';
}
return body['message'];
} catch (_) {
return null;
}
}
return null;
} catch (err) {
print(err);
return null;
}
}

static Future<String> getLaminarTokens(String address) async {
try {
Response res = await post(
Expand Down
2 changes: 1 addition & 1 deletion lib/service/substrateApi/acala/apiAcala.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ApiAcala {
IosDeviceInfo info = await deviceInfo.iosInfo;
deviceId = info.identifierForVendor;
}
String res = await FaucetApi.getAcalaTokens(address, deviceId);
String res = await FaucetApi.getAcalaTokensV2(address, deviceId);
return res;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/utils/i18n/staking.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const Map<String, String> enStaking = {
'filter': 'Filter with Address/Name',
'sort': 'Sort by',
'nominate.active': 'Active',
'nominate.over': 'Oversubscribed',
'nominate.inactive': 'Inactive',
'nominate.waiting': 'Waiting',
'phala': 'Phala Airdrop',
Expand Down Expand Up @@ -143,6 +144,7 @@ const Map<String, String> zhStaking = {
'filter': '地址/名称筛选',
'sort': '排序',
'nominate.active': '活跃',
'nominate.over': '超额认购',
'nominate.inactive': '不活跃',
'nominate.waiting': '等待',
'phala': 'Phala 空投',
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: PolkaWallet made with Flutter.
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.3+1033
version: 1.0.4+1041

environment:
sdk: ">=2.7.0 <3.0.0"
Expand Down

0 comments on commit 493f9dd

Please sign in to comment.