Skip to content

Commit

Permalink
feat: Add support for InputNumber in ui-app.
Browse files Browse the repository at this point in the history
Required for polkadot-js/apps PR #144, specifically commit polkadot-js/apps@f2da789
  • Loading branch information
ltfschoen committed Aug 18, 2018
1 parent ae25ece commit 103f8a0
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/type-extrinsics/src/democracy.ts
Expand Up @@ -12,7 +12,7 @@ const propose: CreateItemOptions = {
description: 'Propose',
params: [
param('proposal', 'Proposal'),
param('value', 'Balance')
param('value', 'InputNumber')
],
type: []
};
Expand Down
2 changes: 1 addition & 1 deletion packages/type-extrinsics/src/staking.ts
Expand Up @@ -28,7 +28,7 @@ const transfer: CreateItemOptions = {
description: 'Transfer',
params: [
param('recipient', 'AccountId'),
param('value', 'Balance')
param('value', 'InputNumber')
],
type: []
};
Expand Down
3 changes: 3 additions & 0 deletions packages/type-params/src/decode/value/index.ts
Expand Up @@ -76,6 +76,9 @@ export default function decodeValue (decode: Decoder, type: Param$Type, _input:
case 'Hash':
return u8a(input, 256, 0);

case 'InputNumber':
return bn(input, sizes.InputNumber.get(version) || defaultSizes.InputNumber);

case 'KeyValue':
case 'StorageKeyValue':
return keyValue(input);
Expand Down
3 changes: 3 additions & 0 deletions packages/type-params/src/encode/type/index.ts
Expand Up @@ -60,6 +60,9 @@ export default function encodeType (type: Param$Type, value: any, version: Encod
case 'AccountIndex':
return bnToU8a(value, sizes.AccountIndex.get(version) || defaultSizes.Balance, true);

case 'InputNumber':
return bnToU8a(value, sizes.InputNumber.get(version) || defaultSizes.InputNumber, true);

case 'KeyValue':
case 'StorageKeyValue':
return keyValue(value);
Expand Down
8 changes: 7 additions & 1 deletion packages/type-params/src/sizes.ts
Expand Up @@ -15,7 +15,13 @@ const AccountIndex: Map<EncodingVersions, SizeType> = new Map([
['poc-1' as EncodingVersions, 64 as SizeType]
]);

const InputNumber: Map<EncodingVersions, SizeType> = new Map([
['latest' as EncodingVersions, sizes.InputNumber],
['poc-1' as EncodingVersions, 64 as SizeType]
]);

export default {
AccountIndex,
Balance
Balance,
InputNumber
};
2 changes: 1 addition & 1 deletion packages/type-params/src/types.d.ts
Expand Up @@ -14,7 +14,7 @@ export type EncodingVersions = 'poc-1' | 'latest';
// - @polkadot/storage/key/params.ts
// - decode/value/index.js
// - encode/type/index.js
export type Param$Type = 'AccountId' | 'AccountIndex' | 'Balance' | 'BlockNumber' | 'bool' | 'Bytes' | 'Call' | 'CandidateReceipt' | 'Code' | 'Digest' | 'Gas' | 'Hash' | 'Header' | 'KeyValue' | 'MisbehaviorReport' | 'ParachainId' | 'PrendingExtrinsics' | 'PropIndex' | 'Proposal' | 'ReferendumIndex' | 'SessionKey' | 'Signature' | 'SignedBlock' | 'StorageKey' | 'StorageKeyValue' | 'StorageResult' | 'StorageResultSet' | 'String' | 'Timestamp' | 'u32' | 'u64' | 'u128' | 'VoteIndex' | 'VoteThreshold';
export type Param$Type = 'AccountId' | 'AccountIndex' | 'Balance' | 'BlockNumber' | 'bool' | 'Bytes' | 'Call' | 'CandidateReceipt' | 'Code' | 'Digest' | 'Gas' | 'Hash' | 'Header' | 'InputNumber' | 'KeyValue' | 'MisbehaviorReport' | 'ParachainId' | 'PrendingExtrinsics' | 'PropIndex' | 'Proposal' | 'ReferendumIndex' | 'SessionKey' | 'Signature' | 'SignedBlock' | 'StorageKey' | 'StorageKeyValue' | 'StorageResult' | 'StorageResultSet' | 'String' | 'Timestamp' | 'u32' | 'u64' | 'u128' | 'VoteIndex' | 'VoteThreshold';

export type Param$Type$Array = Array<Param$Type | Array<Param$Type | Array<Param$Type>>>;

Expand Down
4 changes: 3 additions & 1 deletion packages/type-primitives/src/sizes.ts
Expand Up @@ -7,9 +7,11 @@ export type SizeType = 32 | 64 | 128;
const Balance: SizeType = 128;
const BlockNumber: SizeType = 64;
const AccountIndex: SizeType = 32;
const InputNumber: SizeType = 128;

export default {
AccountIndex,
Balance,
BlockNumber
BlockNumber,
InputNumber
};
3 changes: 3 additions & 0 deletions packages/type-storage/src/key/params.ts
Expand Up @@ -61,6 +61,9 @@ export default function formatParams (params: Params, values: Storage$Key$Value[
case 'AccountIndex':
return bnToU8a((value as BN), sizes.AccountIndex, true);

case 'InputNumber':
return bnToU8a((value as BN), sizes.InputNumber, true);

case 'ParachainId':
case 'PropIndex':
case 'ReferendumIndex':
Expand Down

0 comments on commit 103f8a0

Please sign in to comment.