Skip to content

Commit

Permalink
Merge pull request #24 from polkawallet-io/develop
Browse files Browse the repository at this point in the history
release 0.4.7
  • Loading branch information
RomeroYang authored Jun 6, 2022
2 parents 4335c5c + cddb527 commit 1684ee1
Show file tree
Hide file tree
Showing 9 changed files with 409 additions and 333 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.7] - 20220606

* bump polkadot-js/api v8.5.1
* update tx error message parsing

## [0.4.6] - 20220526

* add dapp auth
Expand Down
6 changes: 3 additions & 3 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ packages:
name: mobx
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
version: "2.0.7"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -262,7 +262,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.4.2"
version: "0.4.6"
process:
dependency: transitive
description:
Expand Down Expand Up @@ -365,7 +365,7 @@ packages:
name: webview_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
version: "3.0.4"
webview_flutter_android:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion js_api/dist/main.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions js_api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@polkawallet/js-api",
"version": "0.4.2",
"version": "0.4.6",
"main": "index.js",
"license": "Apache-2.0",
"keywords": [
Expand All @@ -24,13 +24,13 @@
"build-dev": "webpack --mode development"
},
"resolutions": {
"@polkadot/api": "^8.1.1",
"@polkadot/api": "^8.5.1",
"bn.js": "4.12.0"
},
"dependencies": {
"@polkadot/api": "^8.1.1",
"@polkadot/extension-dapp": "^0.43.1",
"@polkadot/ui-shared": "^2.0.1",
"@polkadot/api": "^8.5.1",
"@polkadot/extension-dapp": "^0.43.2",
"@polkadot/ui-shared": "^2.2.1",
"@walletconnect/client": "2.0.0-alpha.26",
"bn.js": "^5.1.2",
"oo7-substrate": "^0.8.0",
Expand Down
4 changes: 2 additions & 2 deletions js_api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ async function connect(nodes: string[]) {
});
if (!(<any>window).api) {
(<any>window).api = res;
const url = nodes[(<any>res)._options.provider.__private_29_endpointIndex];
const url = nodes[(<any>res)._options.provider.__private_23_endpointIndex];
send("log", `${url} wss connected success`);
resolve(url);
} else {
res.disconnect();
const url = nodes[(<any>res)._options.provider.__private_29_endpointIndex];
const url = nodes[(<any>res)._options.provider.__private_23_endpointIndex];
send("log", `${url} wss success and disconnected`);
resolve(url);
}
Expand Down
36 changes: 22 additions & 14 deletions js_api/src/service/keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,29 +187,18 @@ function _extractEvents(api: ApiPromise, result: SubmittableResult) {
}

let success = false;
let error: DispatchError["type"] = "";
let error: string;
result.events
.filter((event) => !!event.event)
.map(({ event: { data, method, section } }) => {
if (section === "system" && method === "ExtrinsicFailed") {
const [dispatchError] = (data as unknown) as ITuple<[DispatchError]>;
let message = dispatchError.type;
error = _getDispatchError(dispatchError);

if (dispatchError.isModule) {
try {
const mod = dispatchError.asModule;
const err = api.registry.findMetaError(new Uint8Array([mod.index.toNumber(), mod.error.toNumber()]));

message = `${err.section}.${err.name}`;
} catch (error) {
// swallow error
}
}
(<any>window).send("txUpdateEvent", {
title: `${section}.${method}`,
message,
message: error,
});
error = message;
} else {
(<any>window).send("txUpdateEvent", {
title: `${section}.${method}`,
Expand All @@ -223,6 +212,25 @@ function _extractEvents(api: ApiPromise, result: SubmittableResult) {
return { success, error };
}

export function _getDispatchError(dispatchError: DispatchError): string {
let message: string = dispatchError.type;

if (dispatchError.isModule) {
try {
const mod = dispatchError.asModule;
const error = dispatchError.registry.findMetaError(mod);

message = `${error.section}.${error.name}`;
} catch (error) {
// swallow
}
} else if (dispatchError.isToken) {
message = `${dispatchError.type}.${dispatchError.asToken.type}`;
}

return message;
}

/**
* sign and send extrinsic to network and wait for result.
*/
Expand Down
Loading

0 comments on commit 1684ee1

Please sign in to comment.