From c539430a0bf2569a5008fca0f4a38d05b3a1ed2f Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 18 Feb 2020 09:00:08 +0100 Subject: [PATCH] 2.4 (#539) --- CHANGELOG.md | 7 ++++--- lerna.json | 2 +- package.json | 2 +- packages/keyring/package.json | 6 +++--- packages/keyring/src/testing.ts | 4 ++-- packages/util-crypto/package.json | 5 +++-- packages/util/package.json | 6 ++---- packages/util/src/format/formatBalance.spec.ts | 14 ++++++++++---- packages/util/src/format/formatBalance.ts | 5 +++-- yarn.lock | 8 ++++---- 10 files changed, 33 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c150dc7ec..f8135b7ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ -# 2.4.0-beta.x +# 2.4.1 Feb 18, 2020 - Ensure that `formatBalance` does not apply unit overrides apply when no SI is applicable -- Adjust `formatBalance` to take expanded `withUnit: string | boolean` option where string is an actual unit, e.g. `KSM` -- The `.setSS58Format` on keyring will now just operate on the keyring, not globally. The global `setSS58Format` in `@polkadot/util-crypto` is deprecated. +- Adjust `formatBalance(, )` to take expanded `withUnit: string | boolean` option where string is an actual unit, e.g. `KSM` +- The `decimals` option to `formatBalance` should now be passed as part of the `options` (previous last-param deprecated) +- The `.setSS58Format` on keyring will now just operate on pairs created on the keyring, not globally. The global `setSS58Format` in `@polkadot/util-crypto` will be deprecated. - The deprecated `addressPrefix` option to keyring has been belatedly removed (Use `ss58Format` rather) # 2.3.1 Feb 15, 2020 diff --git a/lerna.json b/lerna.json index d45ab7749..631c797bc 100644 --- a/lerna.json +++ b/lerna.json @@ -9,5 +9,5 @@ "packages": [ "packages/*" ], - "version": "2.4.0-beta.2" + "version": "2.4.0" } diff --git a/package.json b/package.json index 3cabe7e76..3d42d18fc 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ }, "devDependencies": { "@babel/core": "^7.8.4", - "@polkadot/dev": "^0.40.17", + "@polkadot/dev": "^0.40.18", "@polkadot/ts": "^0.2.3" } } diff --git a/packages/keyring/package.json b/packages/keyring/package.json index 86aca17ed..9f0c87a3d 100644 --- a/packages/keyring/package.json +++ b/packages/keyring/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/keyring", - "version": "2.4.0-beta.2", + "version": "2.4.0", "description": "Keyring management", "main": "index.js", "publishConfig": { @@ -28,7 +28,7 @@ "homepage": "https://github.com/polkadot-js/common/tree/master/packages/keyring#readme", "dependencies": { "@babel/runtime": "^7.8.4", - "@polkadot/util": "^2.4.0-beta.2", - "@polkadot/util-crypto": "^2.4.0-beta.2" + "@polkadot/util": "^2.4.0", + "@polkadot/util-crypto": "^2.4.0" } } diff --git a/packages/keyring/src/testing.ts b/packages/keyring/src/testing.ts index 032463de8..d323f54f6 100644 --- a/packages/keyring/src/testing.ts +++ b/packages/keyring/src/testing.ts @@ -73,7 +73,7 @@ export const PAIRS: PairDef[] = [ export default function testKeyring (options: KeyringOptions = {}, isDerived = true): KeyringInstance { const keyring = new Keyring(options); - PAIRS.forEach(({ name, publicKey, secretKey, seed, type }): void => { + PAIRS.forEach(({ name, publicKey, secretKey, seed, type = 'sr25519' }): void => { const meta = { isTesting: true, name: name || seed.replace('//', '_').toLowerCase() @@ -82,7 +82,7 @@ export default function testKeyring (options: KeyringOptions = {}, isDerived = t const pair = !isDerived && !name ? keyring.addFromUri(seed, meta, options.type) : keyring.addPair( - createPair({ toSS58: keyring.encodeAddress, type: type || 'sr25519' }, { publicKey, secretKey }, meta) + createPair({ toSS58: keyring.encodeAddress, type }, { publicKey, secretKey }, meta) ); pair.lock = (): void => { diff --git a/packages/util-crypto/package.json b/packages/util-crypto/package.json index ae49d8f3b..659185bf2 100644 --- a/packages/util-crypto/package.json +++ b/packages/util-crypto/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/util-crypto", - "version": "2.4.0-beta.2", + "version": "2.4.0", "description": "A collection of useful crypto utilities for @polkadot", "main": "index.js", "keywords": [ @@ -26,7 +26,7 @@ "homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-crypto#readme", "dependencies": { "@babel/runtime": "^7.8.4", - "@polkadot/util": "^2.4.0-beta.2", + "@polkadot/util": "^2.4.0", "@polkadot/wasm-crypto": "^1.0.1", "base-x": "^3.0.7", "bip39": "^3.0.2", @@ -40,6 +40,7 @@ "xxhashjs": "^0.2.2" }, "devDependencies": { + "@types/bn.js": "^4.11.6", "@types/bs58": "^4.0.0", "@types/elliptic": "^6.4.12", "@types/pbkdf2": "^3.0.0", diff --git a/packages/util/package.json b/packages/util/package.json index 6dfb7a123..648659d38 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/util", - "version": "2.4.0-beta.2", + "version": "2.4.0", "description": "A collection of useful utilities for @polkadot", "main": "index.js", "keywords": [ @@ -26,12 +26,10 @@ "homepage": "https://github.com/polkadot-js/common/tree/master/packages/util#readme", "dependencies": { "@babel/runtime": "^7.8.4", + "@types/bn.js": "^4.11.6", "bn.js": "^5.1.1", "camelcase": "^5.3.1", "chalk": "^3.0.0", "ip-regex": "^4.1.0" - }, - "devDependencies": { - "@types/bn.js": "^4.11.6" } } diff --git a/packages/util/src/format/formatBalance.spec.ts b/packages/util/src/format/formatBalance.spec.ts index ec9b2631e..f8d63c121 100644 --- a/packages/util/src/format/formatBalance.spec.ts +++ b/packages/util/src/format/formatBalance.spec.ts @@ -16,14 +16,20 @@ describe('formatBalance', (): void => { }); it('formats 123,456,789,000 (decimals=15)', (): void => { + expect( + formatBalance(TESTVAL, { withSi: true, decimals: 15 }) + ).toEqual('123.456µ Unit'); + }); + + it('formats 123,456,789,000 (decimals=15, old style)', (): void => { expect( formatBalance(TESTVAL, { withSi: true }, 15) ).toEqual('123.456µ Unit'); }); - it('formats 123,456,789,000 (decimals=36)', (): void => { + it('formats 123,456,789,000 (decimals=36, option)', (): void => { expect( - formatBalance(TESTVAL, { withSi: true }, 36) + formatBalance(TESTVAL, { withSi: true, decimals: 36 }) ).toEqual('0.123y Unit'); }); @@ -34,13 +40,13 @@ describe('formatBalance', (): void => { something: 'else' }; expect( - formatBalance(compact, { withSi: true }, 15) + formatBalance(compact, { withSi: true, decimals: 15 }) ).toEqual('123.456µ Unit'); }); it('formats 123,456,789,000 (decimals=12)', (): void => { expect( - formatBalance(TESTVAL, { withSi: true }, 12) + formatBalance(TESTVAL, { withSi: true, decimals: 12 }) ).toEqual('123.456m Unit'); }); diff --git a/packages/util/src/format/formatBalance.ts b/packages/util/src/format/formatBalance.ts index 0c1c49acc..78568b282 100644 --- a/packages/util/src/format/formatBalance.ts +++ b/packages/util/src/format/formatBalance.ts @@ -18,6 +18,7 @@ interface Defaults { } interface Options { + decimals?: number; forceUnit?: string; withSi?: boolean; withSiFull?: boolean; @@ -40,7 +41,7 @@ let defaultDecimals = DEFAULT_DECIMALS; let defaultUnit = DEFAULT_UNIT; // Formats a string/number with . notation -function _formatBalance (input?: number | string | BN | ExtToBn, options: Options | boolean = true, decimals: number = defaultDecimals): string { +function _formatBalance (input?: number | string | BN | ExtToBn, options: Options | boolean = true, optDecimals: number = defaultDecimals): string { let text = bnToBn(input).toString(); if (text.length === 0 || text === '0') { @@ -56,7 +57,7 @@ function _formatBalance (input?: number | string | BN | E } // extract options - the boolean case is for backwards-compat - const { forceUnit = undefined, withSi = true, withSiFull = false, withUnit = true } = isBoolean(options) + const { decimals = optDecimals, forceUnit = undefined, withSi = true, withSiFull = false, withUnit = true } = isBoolean(options) ? { withSi: options } : options; diff --git a/yarn.lock b/yarn.lock index 6332ccc2a..aef2eef72 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2016,10 +2016,10 @@ dependencies: "@types/node" ">= 8" -"@polkadot/dev@^0.40.17": - version "0.40.17" - resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.40.17.tgz#493f4a7263797e416b12e6b735b39d428f6c0ef1" - integrity sha512-tAfUlcdOzixa6c4/5fxaXjO4cEmXpGZzx3EAIyqsQw+74FBFVR1BKEeGoGuWetTQfIWKqAMOKsFjF5O6VS+VfA== +"@polkadot/dev@^0.40.18": + version "0.40.18" + resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.40.18.tgz#6ca40304bcc7c75b26c0190d60cb5b892a512dc5" + integrity sha512-SEkmrdZPYcnFzXnfpIjnvNfrwdBS3uAenEt8ZYBMkay59+XgFnPKi7xKV92x5iGYEiAXfcKFYjCAN0Nk2rXV5Q== dependencies: "@babel/cli" "^7.8.4" "@babel/core" "^7.8.4"