Simplify address determination
This commit is contained in:
parent
18e90dbef2
commit
c550c88a06
@ -14,7 +14,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/rx-react": "^0.2.8",
|
||||
"@polkadot/util": "^0.18.6",
|
||||
"@polkadot/util": "^0.19.1",
|
||||
"react": "^16.3.1",
|
||||
"react-dom": "^16.3.1",
|
||||
"semantic-ui-css": "^2.3.1",
|
||||
|
||||
@ -15,8 +15,8 @@
|
||||
"devDependencies": {
|
||||
"@polkadot/rx-react": "^0.2.8",
|
||||
"@polkadot/ui-react": "^0.9.10",
|
||||
"@polkadot/util": "^0.18.6",
|
||||
"@polkadot/util-keyring": "^0.18.6",
|
||||
"@polkadot/util": "^0.19.1",
|
||||
"@polkadot/util-keyring": "^0.19.1",
|
||||
"react": "^16.3.1",
|
||||
"react-dom": "^16.3.1",
|
||||
"semantic-ui-css": "^2.3.1",
|
||||
|
||||
@ -18,13 +18,7 @@ type Props = BaseProps & {
|
||||
};
|
||||
|
||||
export default function Account ({ className, label, subject, style }: Props) {
|
||||
const AccountBalance = withObservableParams(Balance, subject, (pair: KeyringPair) => {
|
||||
if (!pair) {
|
||||
return new Uint8Array([]);
|
||||
}
|
||||
|
||||
return pair.publicKey();
|
||||
});
|
||||
const AccountBalance = withObservableParams(Balance, subject);
|
||||
|
||||
return (
|
||||
<div
|
||||
|
||||
@ -13,6 +13,8 @@ import withObservable from '@polkadot/rx-react/with/observable';
|
||||
|
||||
import StakingTransfer from '../StakingTransfer';
|
||||
import encode from '../encode';
|
||||
import extrinsics from '../extrinsics';
|
||||
import keyring from '../keyring';
|
||||
import { extrinsicName, senderAddr, senderIndex } from '../subjects';
|
||||
import ErrorComponent from './Error';
|
||||
|
||||
@ -31,7 +33,10 @@ function CallDisplay ({ className, style, value }: Props) {
|
||||
|
||||
const Component = COMPONENTS[value] || ErrorComponent;
|
||||
const onSubmit = () => {
|
||||
encode(senderAddr.getValue(), senderIndex.getValue(), value, Component.getValues());
|
||||
const extrinsic = extrinsics[value];
|
||||
const sender = keyring.getPair(senderAddr.getValue());
|
||||
|
||||
encode(extrinsic, sender, senderIndex.getValue(), Component.getValues());
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@ -16,8 +16,9 @@ type Props = BaseProps & {
|
||||
pair: KeyringPair
|
||||
};
|
||||
|
||||
export default function PairDisplay ({ className, name, pair, style }: Props): React$Node {
|
||||
export default function PairDisplay ({ className, pair, style }: Props): React$Node {
|
||||
const publicKey = pair.publicKey();
|
||||
const { name } = pair.getMeta();
|
||||
|
||||
return (
|
||||
<div
|
||||
|
||||
@ -17,21 +17,24 @@ type Props = BaseProps & {
|
||||
subject: rxjs$Subject
|
||||
};
|
||||
|
||||
const testOptions = Object.keys(keyring).map((name) => ({
|
||||
text: (
|
||||
<PairDisplay
|
||||
key={name}
|
||||
name={name}
|
||||
pair={keyring[name]}
|
||||
/>
|
||||
),
|
||||
value: name
|
||||
}));
|
||||
const testOptions = keyring.getPairs().map((pair) => {
|
||||
const publicKey = pair.publicKey();
|
||||
|
||||
return {
|
||||
text: (
|
||||
<PairDisplay
|
||||
key={publicKey.toString()}
|
||||
pair={pair}
|
||||
/>
|
||||
),
|
||||
value: publicKey
|
||||
};
|
||||
});
|
||||
|
||||
export default function InputAddress (props: Props): React$Node {
|
||||
const onChange = (event, { value }) => {
|
||||
if (props.subject) {
|
||||
props.subject.next(keyring[value]);
|
||||
props.subject.next(value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -15,13 +15,7 @@ import { senderAddr, senderIndex } from './subjects';
|
||||
|
||||
type Props = BaseProps & {};
|
||||
|
||||
const SenderNonce = withObservableParams(RxNonce, senderAddr, (pair: KeyringPair) => {
|
||||
if (!pair) {
|
||||
return new Uint8Array([]);
|
||||
}
|
||||
|
||||
return pair.publicKey();
|
||||
});
|
||||
const SenderNonce = withObservableParams(RxNonce, senderAddr);
|
||||
const onNonceChange = (value: Uint8Array) => {
|
||||
if (!value || value.length !== 8) {
|
||||
return;
|
||||
|
||||
@ -3,12 +3,12 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import { amount } from './subjects';
|
||||
import { recipientAddr } from '../subjects';
|
||||
import { amount } from './subjects';
|
||||
|
||||
export default function getValues (): Array<mixed> {
|
||||
return [
|
||||
recipientAddr.getValue().publicKey(),
|
||||
recipientAddr.getValue(),
|
||||
amount.getValue()
|
||||
];
|
||||
}
|
||||
|
||||
@ -6,16 +6,16 @@
|
||||
// TODO: Move to API
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { Extrinsic } from '../extrinsics/types';
|
||||
|
||||
const bnToU8a = require('@polkadot/util/bn/toU8a');
|
||||
const u8aConcat = require('@polkadot/util/u8a/concat');
|
||||
const u8aToHex = require('@polkadot/util/u8a/toHex');
|
||||
|
||||
const extrinsics = require('../extrinsics');
|
||||
const encodeParams = require('./params');
|
||||
|
||||
// flowlint-next-line unclear-type:off
|
||||
module.exports = function encode (sender: KeyringPair, nonce: number | BN, method: string, values: Array<mixed>): Uint8Array {
|
||||
const { index, params } = extrinsics[method];
|
||||
module.exports = function encode (extrinsic: Extrinsic, sender: KeyringPair, nonce: number | BN, values: Array<mixed>): Uint8Array {
|
||||
const { index, params } = extrinsic;
|
||||
const encodedParams = encodeParams(values, params);
|
||||
const message = u8aConcat(
|
||||
sender.publicKey(),
|
||||
@ -25,5 +25,8 @@ module.exports = function encode (sender: KeyringPair, nonce: number | BN, metho
|
||||
);
|
||||
const signature = sender.sign(message);
|
||||
|
||||
console.log('message =', u8aToHex(message));
|
||||
console.log('signature =', u8aToHex(signature));
|
||||
|
||||
return u8aConcat(message, signature);
|
||||
};
|
||||
|
||||
27
yarn.lock
27
yarn.lock
@ -1358,6 +1358,16 @@
|
||||
tweetnacl "^1.0.0"
|
||||
xxhashjs "^0.2.2"
|
||||
|
||||
"@polkadot/util-crypto@^0.19.1":
|
||||
version "0.19.1"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.19.1.tgz#95927de2f8a4384f05b872132e00bfd34aa1ea77"
|
||||
dependencies:
|
||||
babel-runtime "^6.26.0"
|
||||
blakejs "^1.1.0"
|
||||
js-sha3 "^0.7.0"
|
||||
tweetnacl "^1.0.0"
|
||||
xxhashjs "^0.2.2"
|
||||
|
||||
"@polkadot/util-keyring@^0.18.4":
|
||||
version "0.18.4"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util-keyring/-/util-keyring-0.18.4.tgz#0e2bdbb3700275025632f42171a3fecacde513e3"
|
||||
@ -1374,6 +1384,14 @@
|
||||
"@polkadot/util-crypto" "^0.18.6"
|
||||
babel-runtime "^6.26.0"
|
||||
|
||||
"@polkadot/util-keyring@^0.19.1":
|
||||
version "0.19.1"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util-keyring/-/util-keyring-0.19.1.tgz#dbf6e9efbe1dd4de982367c279b3193584db414f"
|
||||
dependencies:
|
||||
"@polkadot/util" "^0.19.1"
|
||||
"@polkadot/util-crypto" "^0.19.1"
|
||||
babel-runtime "^6.26.0"
|
||||
|
||||
"@polkadot/util-rlp@^0.18.5":
|
||||
version "0.18.5"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util-rlp/-/util-rlp-0.18.5.tgz#d06a165a1120f293056f81128f93f494ebe7b390"
|
||||
@ -1417,6 +1435,15 @@
|
||||
deasync "^0.1.12"
|
||||
ip-regex "^2.1.0"
|
||||
|
||||
"@polkadot/util@^0.19.1":
|
||||
version "0.19.1"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.19.1.tgz#e19dc51b3d998b489ed26738a3a1e0cded65c020"
|
||||
dependencies:
|
||||
babel-runtime "^6.26.0"
|
||||
bn.js "^4.11.8"
|
||||
deasync "^0.1.12"
|
||||
ip-regex "^2.1.0"
|
||||
|
||||
"@types/node@*":
|
||||
version "9.6.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.6.2.tgz#e49ac1adb458835e95ca6487bc20f916b37aff23"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user