Skip to content

Commit 9023109

Browse files
committed
Merge branch 'develop'
2 parents 075d9f2 + e19f65c commit 9023109

File tree

9 files changed

+116
-81
lines changed

9 files changed

+116
-81
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [0.3.7] - 20211101
2+
3+
* bump polkadot-js/api v6.5.2
4+
* fix gov referendum data parsing
5+
16
## [0.3.6] - 20211025
27

38
* bump polkadot-js/api v6.5.1

js_api/dist/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js_api/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@polkawallet/js-api",
3-
"version": "0.3.6",
3+
"version": "0.3.7",
44
"main": "index.js",
55
"license": "Apache-2.0",
66
"keywords": [
@@ -24,10 +24,10 @@
2424
"build-dev": "webpack --mode development"
2525
},
2626
"resolutions": {
27-
"@polkadot/api": "^6.5.1"
27+
"@polkadot/api": "^6.5.2"
2828
},
2929
"dependencies": {
30-
"@polkadot/api": "^6.5.1",
30+
"@polkadot/api": "^6.5.2",
3131
"@polkadot/extension-dapp": "^0.40.3",
3232
"@polkadot/ui-shared": "0.86.2",
3333
"@walletconnect/client": "2.0.0-alpha.26",

js_api/src/service/gov.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
import { ApiPromise } from "@polkadot/api";
22
import { DeriveCollectiveProposal, DeriveReferendumExt, DeriveCouncilVotes } from "@polkadot/api-derive/types";
33
import { SubmittableExtrinsic } from "@polkadot/api/types";
4-
import { GenericCall, getTypeDef, Option, Bytes } from "@polkadot/types";
5-
import { OpenTip, AccountId, FunctionMetadataLatest } from "@polkadot/types/interfaces";
4+
import { getTypeDef, Option, Bytes } from "@polkadot/types";
5+
import { OpenTip, AccountId } from "@polkadot/types/interfaces";
66
import { formatBalance, stringToU8a, BN_ZERO, hexToString } from "@polkadot/util";
77
import BN from "bn.js";
88

99
import { approxChanges } from "../utils/referendumApproxChanges";
1010

11-
function _extractMetaData(value: FunctionMetadataLatest) {
12-
const params = GenericCall.filterOrigin(value).map(({ name, type }) => ({
11+
function _extractMetaData(value: any) {
12+
const params = value.meta.args.map(({ name, type }) => ({
1313
name: name.toString(),
1414
type: getTypeDef(type.toString()),
1515
}));
1616
const values = value.args.map((value) => ({
1717
isValid: true,
1818
value,
1919
}));
20-
const hash = value.hash;
20+
const hash = value.hash.toHex();
21+
2122
return { hash, params, values };
2223
}
2324

@@ -33,15 +34,15 @@ function _transfromProposalMeta(proposal: any): {} {
3334
}
3435
}
3536
const json = proposal.toHuman();
37+
let args: string[] = Object.values(json.args);
3638
if (json.method == "setCode") {
37-
const args = json.args;
38-
json.args = [args[0].slice(0, 16) + "..." + args[0].slice(args[0].length - 16)];
39+
args = [json.args.code.substring(0, 64)];
3940
}
4041
return {
4142
callIndex: proposal.toJSON().callIndex,
4243
method: json.method,
4344
section: json.section,
44-
args: json.args,
45+
args,
4546
meta: {
4647
...meta.toJSON(),
4748
documentation: doc,
@@ -59,16 +60,12 @@ async function fetchReferendums(api: ApiPromise, address: string) {
5960
let proposalMeta: any = {};
6061
let parsedMeta: any = {};
6162
if (image && image.proposal) {
62-
proposalMeta = _extractMetaData(image.proposal.registry.findMetaCall(image.proposal.callIndex).meta);
63+
proposalMeta = _extractMetaData(image.proposal);
6364
parsedMeta = _transfromProposalMeta(image.proposal);
64-
image.proposal = image.proposal.toHuman() as any;
65-
if (image.proposal?.method == "setCode") {
66-
const args = image.proposal.args;
67-
image.proposal = {
68-
...image.proposal,
69-
args: [(args[0].toString().slice(0, 16) + "..." + args[0].toString().slice(args[0].toString().length - 16)) as any],
70-
} as any;
71-
}
65+
image.proposal = {
66+
...image.proposal.toHuman(),
67+
args: parsedMeta.args,
68+
} as any;
7269
}
7370

7471
const changes = approxChanges(status.threshold, sqrtElectorate, {

js_api/yarn.lock

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,31 +1946,31 @@
19461946
dependencies:
19471947
pino "^6.7.0"
19481948

1949-
"@polkadot/[email protected].1":
1950-
version "6.5.1"
1951-
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-6.5.1.tgz#c2e7d632c3c156355218650e6414504d9a154b17"
1952-
integrity sha512-OwiCYcak3fqiZtE28FbqEd+ZTck9LmsEk01VPQigwSgNu/qbiuKGZ+MurK6yWy8sHbFdcDLPR07/iD5/fhQZRw==
1949+
"@polkadot/[email protected].2":
1950+
version "6.5.2"
1951+
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-6.5.2.tgz#1c14c4cda13bab958b55ce8973aed2a4388d400d"
1952+
integrity sha512-QD7xegHVLIrDxbuBiAF4wGzqXc/pXsfwTLpkVW1bT7Aa8pXWVTdahh4HCcgOq7c1i01QS2lQE21/4SSLG7KzUA==
19531953
dependencies:
19541954
"@babel/runtime" "^7.15.4"
1955-
"@polkadot/api" "6.5.1"
1956-
"@polkadot/rpc-core" "6.5.1"
1957-
"@polkadot/types" "6.5.1"
1955+
"@polkadot/api" "6.5.2"
1956+
"@polkadot/rpc-core" "6.5.2"
1957+
"@polkadot/types" "6.5.2"
19581958
"@polkadot/util" "^7.6.1"
19591959
"@polkadot/util-crypto" "^7.6.1"
19601960
rxjs "^7.4.0"
19611961

1962-
"@polkadot/[email protected].1", "@polkadot/api@^6.5.1":
1963-
version "6.5.1"
1964-
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-6.5.1.tgz#c6c46ed8274114d56652574bfc64a01610401490"
1965-
integrity sha512-hxnXb4qFlRbqBKnWgvNtRAukDRthAcLjhh1IY9oQ6WRJipdb2wMtNz6MY06gLI0MVGv9u2fOC6Rhd2JGo4CKZg==
1962+
"@polkadot/[email protected].2", "@polkadot/api@^6.5.2":
1963+
version "6.5.2"
1964+
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-6.5.2.tgz#40a2a2545cc3be19ce35b4c4b688c0a2055576bd"
1965+
integrity sha512-UNR8pynzPzS1GxpCoLh2a/iPf9lPYY03q0ZLZG/qYYFR+njeD7/4B5e+yEMHIDKS/+XAvM5zXDEbEtxHMiCR9A==
19661966
dependencies:
19671967
"@babel/runtime" "^7.15.4"
1968-
"@polkadot/api-derive" "6.5.1"
1968+
"@polkadot/api-derive" "6.5.2"
19691969
"@polkadot/keyring" "^7.6.1"
1970-
"@polkadot/rpc-core" "6.5.1"
1971-
"@polkadot/rpc-provider" "6.5.1"
1972-
"@polkadot/types" "6.5.1"
1973-
"@polkadot/types-known" "6.5.1"
1970+
"@polkadot/rpc-core" "6.5.2"
1971+
"@polkadot/rpc-provider" "6.5.2"
1972+
"@polkadot/types" "6.5.2"
1973+
"@polkadot/types-known" "6.5.2"
19741974
"@polkadot/util" "^7.6.1"
19751975
"@polkadot/util-crypto" "^7.6.1"
19761976
eventemitter3 "^4.0.7"
@@ -2016,45 +2016,45 @@
20162016
dependencies:
20172017
"@babel/runtime" "^7.15.4"
20182018

2019-
"@polkadot/[email protected].1":
2020-
version "6.5.1"
2021-
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-6.5.1.tgz#0a2ecb78b38c63f0831c7fb5363d9cc1fb72ec0e"
2022-
integrity sha512-teWI8iumsAMHF1vgMzbRVqpSTfVcNIG7bRwSlGoy4V4ZT8dS5LjOYCR7Eqr19wRuef1DjBY87oiN7e8M2x8jCA==
2019+
"@polkadot/[email protected].2":
2020+
version "6.5.2"
2021+
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-6.5.2.tgz#4dbdf39974284df9f0cc6897654c91b05db66482"
2022+
integrity sha512-ZZRUQqizqH2E4OZ61C1T78KnWm2OiewIZt0SomB5s7zc7ixwcvFltjlWdiuQspG2m4VMb46jFy3pVdkycgrMfg==
20232023
dependencies:
20242024
"@babel/runtime" "^7.15.4"
2025-
"@polkadot/rpc-provider" "6.5.1"
2026-
"@polkadot/types" "6.5.1"
2025+
"@polkadot/rpc-provider" "6.5.2"
2026+
"@polkadot/types" "6.5.2"
20272027
"@polkadot/util" "^7.6.1"
20282028
rxjs "^7.4.0"
20292029

2030-
"@polkadot/[email protected].1":
2031-
version "6.5.1"
2032-
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-6.5.1.tgz#bde30ac49b62edb592b89e19aeea36d23e14b25c"
2033-
integrity sha512-09GId3vknImuEaRH0WDlrP8rsTC/QSIFM7sV55QzjfnLKRct1Fulez0hfFP25orXpjraWqHNZvY1yxniUxK6nA==
2030+
"@polkadot/[email protected].2":
2031+
version "6.5.2"
2032+
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-6.5.2.tgz#359ba68ef5c171191bdd10867e99d3c7b7d71cc5"
2033+
integrity sha512-MFphpbI9zsYKGFb2mXkeOhWRiyDZxKYTyViVB5kE0YeMMl1DHR3YVfjR6t+K5H1A++iwh3xilkyZ8imcfTK/BQ==
20342034
dependencies:
20352035
"@babel/runtime" "^7.15.4"
2036-
"@polkadot/types" "6.5.1"
2036+
"@polkadot/types" "6.5.2"
20372037
"@polkadot/util" "^7.6.1"
20382038
"@polkadot/util-crypto" "^7.6.1"
20392039
"@polkadot/x-fetch" "^7.6.1"
20402040
"@polkadot/x-global" "^7.6.1"
20412041
"@polkadot/x-ws" "^7.6.1"
20422042
eventemitter3 "^4.0.7"
20432043

2044-
"@polkadot/[email protected].1":
2045-
version "6.5.1"
2046-
resolved "https://registry.yarnpkg.com/@polkadot/types-known/-/types-known-6.5.1.tgz#753af9a6c4188accb761639505e3e5cd7e5bc176"
2047-
integrity sha512-eIgk836zlA5KnhK6UotXYr/I9O12xxhNcKXTcA+8NY6ek2xQWlT9VGuMk4wTF4qU1sV/fhOFIDeoNrT7AgSagg==
2044+
"@polkadot/[email protected].2":
2045+
version "6.5.2"
2046+
resolved "https://registry.yarnpkg.com/@polkadot/types-known/-/types-known-6.5.2.tgz#a5b3afe7ddf9fc4a87f1b391d6d7058eb4e03ae0"
2047+
integrity sha512-5mFcsAJDL10pwTRI2ODNYvzeB1pQsSbYakI323BkA9iWxNSDYgHNU9prgEAnbO6VXP31HMX86ZDGhEm/XpGo4A==
20482048
dependencies:
20492049
"@babel/runtime" "^7.15.4"
20502050
"@polkadot/networks" "^7.6.1"
2051-
"@polkadot/types" "6.5.1"
2051+
"@polkadot/types" "6.5.2"
20522052
"@polkadot/util" "^7.6.1"
20532053

2054-
"@polkadot/[email protected].1":
2055-
version "6.5.1"
2056-
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-6.5.1.tgz#6d348b7c37ec351506e952ee16f696ecf4a56725"
2057-
integrity sha512-EiW/5vbR6sP20Yq7wto7Ozepie6YzGjPCH4IPLkGrPsDaMegbwNRvEV+5AbCYvEPKF6LJoaRPUcF/WQxncVonA==
2054+
"@polkadot/[email protected].2":
2055+
version "6.5.2"
2056+
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-6.5.2.tgz#76f5fb1b35ae20530554869b9a859811b4048b28"
2057+
integrity sha512-QDE5SxyW/Veq0IB8zT0RaBJTedmVkxhR8EykwslJiRuHSBz/HZjtEhcnA44c8fdKWKkbURklbX2vlWd7d2w4jQ==
20582058
dependencies:
20592059
"@babel/runtime" "^7.15.4"
20602060
"@polkadot/util" "^7.6.1"

lib/plugin/index.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,15 @@ abstract class PolkawalletPlugin implements PolkawalletPluginBase {
5151
'${balance_cache_key}_${basic.name}_$pubKey';
5252

5353
Future<void> updateNetworkState() async {
54-
final state = await Future.wait([
55-
sdk.api.service.setting.queryNetworkConst(),
56-
sdk.api.service.setting.queryNetworkProps(),
57-
]);
58-
_cache.write(_getNetworkCacheKey(net_const_cache_key), state[0]);
59-
_cache.write(_getNetworkCacheKey(net_state_cache_key), state[1]);
54+
// final state = await Future.wait([
55+
// sdk.api.service.setting.queryNetworkConst(),
56+
// sdk.api.service.setting.queryNetworkProps(),
57+
// ]);
58+
final state = await sdk.api.service.setting.queryNetwork();
59+
if (state != null) {
60+
_cache.write(_getNetworkCacheKey(net_const_cache_key), state["const"]);
61+
_cache.write(_getNetworkCacheKey(net_state_cache_key), state["props"]);
62+
}
6063
}
6164

6265
void _updateBalances(KeyPairData acc, BalanceData data,

lib/service/setting.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ class ServiceSetting {
77

88
final SubstrateService serviceRoot;
99

10+
Future<Map?> queryNetwork() async {
11+
// fetch network info
12+
List res = await serviceRoot.webView!.evalJavascript(
13+
'Promise.all([settings.getNetworkProperties(api), api.rpc.system.chain(),settings.getNetworkConst(api)])');
14+
// List<dynamic> res = await Future.wait([
15+
// serviceRoot.webView!.evalJavascript('settings.getNetworkProperties(api)'),
16+
// serviceRoot.webView!.evalJavascript('api.rpc.system.chain()'),
17+
// ]);
18+
19+
if (res[0] == null || res[1] == null || res[2] == null) {
20+
return null;
21+
}
22+
23+
final Map props = {"props": res[0], "const": res[2]};
24+
props["props"]['name'] = res[1];
25+
return props;
26+
}
27+
1028
Future<Map> queryNetworkConst() async {
1129
final dynamic res = await serviceRoot.webView!
1230
.evalJavascript('settings.getNetworkConst(api)');

lib/webviewWithExtension/webviewWithExtension.dart

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:async';
22
import 'dart:convert';
3+
import 'dart:io';
34

45
import 'package:flutter/cupertino.dart';
56
import 'package:flutter/foundation.dart';
@@ -93,6 +94,27 @@ class _WebViewWithExtensionState extends State<WebViewWithExtension> {
9394
return Future(() => "");
9495
}
9596

97+
Future<void> _onFinishLoad(String url) async {
98+
if (_loadingFinished) return;
99+
setState(() {
100+
_loadingFinished = true;
101+
});
102+
103+
if (widget.onPageFinished != null) {
104+
widget.onPageFinished!(url);
105+
}
106+
print('Page loaded: $url');
107+
108+
print('Inject extension js code...');
109+
final jsCode = await rootBundle
110+
.loadString('packages/polkawallet_sdk/js_as_extension/dist/main.js');
111+
_controller.evaluateJavascript(jsCode);
112+
print('js code injected');
113+
if (widget.onExtensionReady != null) {
114+
widget.onExtensionReady!();
115+
}
116+
}
117+
96118
@override
97119
Widget build(BuildContext context) {
98120
return WebView(
@@ -115,24 +137,14 @@ class _WebViewWithExtensionState extends State<WebViewWithExtension> {
115137
},
116138
),
117139
].toSet(),
118-
onPageFinished: (String url) async {
119-
if (_loadingFinished) return;
120-
setState(() {
121-
_loadingFinished = true;
122-
});
123-
124-
if (widget.onPageFinished != null) {
125-
widget.onPageFinished!(url);
140+
onPageStarted: (String url) {
141+
if (Platform.isAndroid) {
142+
_onFinishLoad(url);
126143
}
127-
print('Page finished loading: $url');
128-
129-
print('Inject extension js code...');
130-
final jsCode = await rootBundle.loadString(
131-
'packages/polkawallet_sdk/js_as_extension/dist/main.js');
132-
_controller.evaluateJavascript(jsCode);
133-
print('js code injected');
134-
if (widget.onExtensionReady != null) {
135-
widget.onExtensionReady!();
144+
},
145+
onPageFinished: (String url) {
146+
if (Platform.isIOS) {
147+
_onFinishLoad(url);
136148
}
137149
},
138150
gestureNavigationEnabled: true,

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: polkawallet_sdk
22
description: Flutter SDK for building plugin package for polkawallet.
3-
version: 0.3.6
3+
version: 0.3.7
44
homepage: https://polkawallet.io
55

66
environment:

0 commit comments

Comments
 (0)