Skip to content

Commit

Permalink
bump polkadot-js/api v5.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
RomeroYang committed Jul 16, 2021
1 parent 0996e11 commit 2aeaddb
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 315 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [0.2.5] - 20210716

* bump polkadot-js/api v5.0.1
* add TokenBalanceData.locked & TokenBalanceData.reserved

## [0.2.4] - 20210706

* fix DApp webView double-callback bug
Expand Down
39 changes: 19 additions & 20 deletions js_api/dist/main.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions js_api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
"build-dev": "webpack -d --mode development"
},
"resolutions": {
"@polkadot/api": "^4.17.1"
"@polkadot/api": "^5.0.1"
},
"dependencies": {
"@polkadot/api": "^4.17.1",
"@polkadot/ui-shared": "0.82.1",
"@polkadot/extension-dapp": "^0.38.7",
"@polkadot/api": "^5.0.1",
"@polkadot/ui-shared": "0.84.1",
"@polkadot/extension-dapp": "^0.39.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/constants/networkSpect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import networks from "@polkadot/networks";
import { allNetworks } from "@polkadot/networks";
import { assert } from "@polkadot/util";

const colors = {
Expand Down Expand Up @@ -111,7 +111,7 @@ export const NETWORK_LIST = Object.freeze(Object.assign({}, SUBSTRATE_NETWORK_LI
export const defaultNetworkKey = SubstrateNetworkKeys.KUSAMA;

function getGenesis(name: string): string {
const network = networks.find(({ network }) => network === name);
const network = allNetworks.find(({ network }) => network === name);
assert(network && network.genesisHash[0], `Unable to find genesisHash for ${name}`);
return network.genesisHash[0];
}
Expand Down
38 changes: 7 additions & 31 deletions js_api/src/service/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,17 @@ let keyring = new Keyring({ ss58Format: 0, type: "sr25519" });
async function genIcons(addresses: string[]) {
return addresses.map((i) => {
const circles = polkadotIcon(i, { isAlternative: false })
.map(
({ cx, cy, fill, r }) =>
`<circle cx='${cx}' cy='${cy}' fill='${fill}' r='${r}' />`
)
.map(({ cx, cy, fill, r }) => `<circle cx='${cx}' cy='${cy}' fill='${fill}' r='${r}' />`)
.join("");
return [
i,
`<svg viewBox='0 0 64 64' xmlns='http://www.w3.org/2000/svg'>${circles}</svg>`,
];
return [i, `<svg viewBox='0 0 64 64' xmlns='http://www.w3.org/2000/svg'>${circles}</svg>`];
});
}

/**
* Get svg icons of pubKeys.
*/
async function genPubKeyIcons(pubKeys: string[]) {
const icons = await genIcons(
pubKeys.map((key) => keyring.encodeAddress(hexToU8a(key), 2))
);
const icons = await genIcons(pubKeys.map((key) => keyring.encodeAddress(hexToU8a(key), 2)));
return icons.map((i, index) => {
i[0] = pubKeys[index];
return i;
Expand Down Expand Up @@ -77,11 +69,7 @@ async function encodeAddress(pubKeys: string[], ss58Formats: number[]) {
/**
* query account address with account index
*/
async function queryAddressWithAccountIndex(
api: ApiPromise,
accIndex: string,
ss58: number
) {
async function queryAddressWithAccountIndex(api: ApiPromise, accIndex: string, ss58: number) {
const num = ss58Decode(accIndex, ss58).toJSON();
const res = await api.query.indices.accounts(num.data);
return res;
Expand All @@ -94,26 +82,14 @@ async function queryAccountsBonded(api: ApiPromise, pubKeys: string[]) {
return Promise.all(
pubKeys
.map((key) => keyring.encodeAddress(hexToU8a(key), 2))
.map((i) =>
Promise.all([api.query.staking.bonded(i), api.query.staking.ledger(i)])
)
).then((ls) =>
ls.map((i, index) => [
pubKeys[index],
i[0],
i[1].toHuman() ? i[1].toHuman()["stash"] : null,
])
);
.map((i) => Promise.all([api.query.staking.bonded(i), api.query.staking.ledger(i)]))
).then((ls) => ls.map((i, index) => [pubKeys[index], i[0], i[1].toHuman() ? i[1].toHuman()["stash"] : null]));
}

/**
* get network native token balance of an address
*/
async function getBalance(
api: ApiPromise,
address: string,
msgChannel: string
) {
async function getBalance(api: ApiPromise, address: string, msgChannel: string) {
const transfrom = (res: any) => {
const lockedBreakdown = res.lockedBreakdown.map((i: any) => {
return {
Expand Down
3 changes: 1 addition & 2 deletions js_api/src/service/keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import BN from "bn.js";
import { parseQrCode, getSigner, makeTx, getSubmittable } from "../utils/QrSigner";
import gov from "./gov";
import metaDataMap from "../constants/networkMetadata";
import { TypeRegistry } from "@polkadot/types";
import { Metadata } from "@polkadot/metadata";
import { Metadata, TypeRegistry } from "@polkadot/types";
import { wrapBytes } from "@polkadot/extension-dapp/wrapBytes";

import { Keyring } from "@polkadot/keyring";
Expand Down
Loading

0 comments on commit 2aeaddb

Please sign in to comment.