Skip to content

Commit

Permalink
remove unused bridge channels
Browse files Browse the repository at this point in the history
  • Loading branch information
RomeroYang committed Dec 6, 2024
1 parent c065acf commit 2b65e93
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 26 deletions.
59 changes: 38 additions & 21 deletions lib/pages/assets/asset/locksDetailPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,38 @@ class LocksDetailPageState extends State<LocksDetailPage> {
final res = await widget.service.plugin.sdk.webView
.evalJavascript('api.derive.chain.bestNumber()');
bestNumber = int.parse(res.toString());
final List locks = await widget.service.plugin.sdk.api.gov
.getDemocracyLocks(widget.service.keyring.current.address);
final List locks = await widget.service.plugin.sdk.api.gov2
.queryReferendaLocks(widget.service.keyring.current.address);
if (mounted && locks != null) {
setState(() {
_locks = locks;
});
}
}

void _onUnlock(List<String> ids) async {
void _onUnlock(List<List<String>> ids) async {
final dic = I18n.of(context).getDic(i18n_full_dic_app, 'assets');
final txs = ids
.map((e) => 'api.tx.democracy.removeVote(${BigInt.parse(e)})')
.toList();
txs.add(
'api.tx.democracy.unlock("${widget.service.keyring.current.address}")');
final List<String> tracks = [];
final txs = ids.map((e) {
if (!tracks.contains(e[0])) {
tracks.add(e[0]);
}
return 'api.tx.convictionVoting.removeVote("${e[0]}", "${e[1]}")';
}).toList();
for (var trackId in tracks) {
txs.add(
'api.tx.convictionVoting.unlock("$trackId", "${widget.service.keyring.current.address}")');
}
final res = await Navigator.of(context).pushNamed(TxConfirmPage.route,
arguments: TxConfirmParams(
txTitle: dic['lock.unlock'],
module: 'utility',
call: 'batch',
txDisplay: {
"actions": ['democracy.removeVote', 'democracy.unlock'],
"actions": [
'convictionVoting.removeVote',
'convictionVoting.unlock'
],
},
params: [],
rawParams: '[[${txs.join(',')}]]'));
Expand Down Expand Up @@ -176,11 +185,11 @@ class LocksDetailPageState extends State<LocksDetailPage> {
final l = widget.service.plugin.balances.native.lockedBreakdown.toList();
l.retainWhere((e) => BigInt.parse(e.amount.toString()) > BigInt.zero);
final locks =
l.where((element) => element.use.contains('ormlvest')).toList();
locks.addAll(
l.where((element) => element.use.contains('democrac')).toList());
l.retainWhere(
(e) => !e.use.contains('ormlvest') && !e.use.contains('democrac'));
l.where((element) => element.use.contains('pyconvot')).toList();
// locks.addAll(
// l.where((element) => element.use.contains('democrac')).toList());
// l.retainWhere(
// (e) => !e.use.contains('ormlvest') && !e.use.contains('democrac'));
if (l.length > 0) {
locks.add(BalanceBreakdownData.fromJson({"amount": 0, "use": ""}));
}
Expand Down Expand Up @@ -226,18 +235,23 @@ class LocksDetailPageState extends State<LocksDetailPage> {
children: locks.map((e) {
final amt = BigInt.parse(e.amount.toString());
Widget Democracchild;
final List<String> unLockIds = [];
final List<List<String>> unLockIds = [];
double maxLockAmount = 0, maxUnlockAmount = 0;
if (e.use.contains('democrac') && _locks.length > 0) {
if (e.use.contains('pyconvot') && _locks.length > 0) {
for (int index = 0;
index < _locks.length;
index++) {
var unlockAt = _locks[index]['unlockAt'];
var unlockAt = _locks[index]['endBlock'];
final amountString = _locks[index]['total']
.toString()
.startsWith('0x')
? _locks[index]['total']
: "0x${_locks[index]['total']}";
final amount = Fmt.balanceDouble(
_locks[index]['balance'].toString(),
amountString,
decimals,
);
if (unlockAt != "0") {
if (unlockAt != "1fffffffffffff") {
BigInt endLeft;
try {
endLeft =
Expand All @@ -249,7 +263,10 @@ class LocksDetailPageState extends State<LocksDetailPage> {
BigInt.from(bestNumber);
}
if (endLeft.toInt() <= 0) {
unLockIds.add(_locks[index]['referendumId']);
unLockIds.add([
_locks[index]['classId'].toString(),
_locks[index]['refId']
]);
if (amount > maxUnlockAmount) {
maxUnlockAmount = amount;
}
Expand Down Expand Up @@ -344,7 +361,7 @@ class LocksDetailPageState extends State<LocksDetailPage> {
claimableAmount, decimals, symbol));
} else if (Democracchild != null) {
return buildItem(
title: 'Democracy',
title: 'Referenda',
child: Democracchild,
hasClaim: maxUnlockAmount - maxLockAmount > 0,
onRedeem: () => _onUnlock(unLockIds));
Expand Down
9 changes: 5 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1075,10 +1075,11 @@ packages:
polkawallet_sdk:
dependency: "direct main"
description:
path: "../../coding/polkawallet/sdk"
relative: true
source: path
version: "0.6.3"
name: polkawallet_sdk
sha256: "260d923ec6bebd38632492446b1d83e97bda08aa28e10fbff8f6b1f1473d7c26"
url: "https://pub.dev"
source: hosted
version: "0.6.4"
polkawallet_ui:
dependency: "direct main"
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ dependency_overrides:
# polkawallet_plugin_evm:
# path: ../../coding/polkawallet/polkawallet_plugin_evm
polkawallet_ui: ^0.5.6
polkawallet_sdk: ^0.6.3+2
polkawallet_sdk: ^0.6.4
# polkawallet_ui:
# path: ../../coding/polkawallet/ui
# polkawallet_sdk:
Expand Down

0 comments on commit 2b65e93

Please sign in to comment.