Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"packages/*"
],
"resolutions": {
"@polkadot/api": "^0.97.0-beta.16",
"@polkadot/api-contract": "^0.97.0-beta.16",
"@polkadot/api": "^0.97.0-beta.19",
"@polkadot/api-contract": "^0.97.0-beta.19",
"@polkadot/keyring": "^1.7.0-beta.7",
"@polkadot/types": "^0.97.0-beta.16",
"@polkadot/types": "^0.97.0-beta.19",
"@polkadot/util": "^1.7.0-beta.7",
"@polkadot/util-crypto": "^1.7.0-beta.7",
"babel-core": "^7.0.0-bridge.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/app-accounts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@babel/runtime": "^7.7.2",
"@polkadot/react-components": "^0.37.0-beta.109",
"@polkadot/react-qr": "^0.47.0-beta.6",
"@polkadot/react-qr": "^0.47.0-beta.7",
"@types/file-saver": "^2.0.0",
"@types/yargs": "^13.0.2",
"babel-plugin-module-resolver": "^3.1.1",
Expand Down
5 changes: 3 additions & 2 deletions packages/app-claims/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { EthereumAddress, EcdsaSignature } from '@polkadot/types/interfaces';

import secp256k1 from 'secp256k1/elliptic';
import { registry } from '@polkadot/react-api';
import { createType } from '@polkadot/types';
import { assert, hexToU8a, stringToU8a, u8aToBuffer, u8aConcat } from '@polkadot/util';
import { keccakAsHex, keccakAsU8a } from '@polkadot/util-crypto';
Expand Down Expand Up @@ -96,8 +97,8 @@ export function recoverFromJSON (signatureJson: string | null): RecoveredSignatu

return {
error: null,
ethereumAddress: createType('EthereumAddress', recoverAddress(msg, parts)),
signature: createType('EcdsaSignature', u8aConcat(parts.signature, new Uint8Array([parts.recovery])))
ethereumAddress: createType(registry, 'EthereumAddress', recoverAddress(msg, parts)),
signature: createType(registry, 'EcdsaSignature', u8aConcat(parts.signature, new Uint8Array([parts.recovery])))
};
} catch (error) {
console.error(error);
Expand Down
2 changes: 1 addition & 1 deletion packages/app-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.7.2",
"@polkadot/api-contract": "^0.97.0-beta.16",
"@polkadot/api-contract": "^0.97.0-beta.19",
"@polkadot/react-components": "^0.37.0-beta.109"
}
}
3 changes: 2 additions & 1 deletion packages/app-contracts/src/ABI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { I18nProps } from '@polkadot/react-components/types';
import React from 'react';
import styled from 'styled-components';
import { Abi } from '@polkadot/api-contract';
import { registry } from '@polkadot/react-api';
import { InputFile, Labelled, Messages } from '@polkadot/react-components';
import { u8aToString } from '@polkadot/util';

Expand Down Expand Up @@ -154,7 +155,7 @@ class ABI extends React.PureComponent<Props, State> {
throw new Error(t('You are using an ABI with an outdated format. Please generate a new one.'));
}

const contractAbi = new Abi(abi);
const contractAbi = new Abi(registry, abi);

this.setState({
contractAbi,
Expand Down
3 changes: 2 additions & 1 deletion packages/app-contracts/src/Codes/Add.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import React from 'react';
import { createType } from '@polkadot/types';
import { registry } from '@polkadot/react-api';
import { Button, Input } from '@polkadot/react-components';

import ContractModal, { ContractModalProps as Props, ContractModalState } from '../Modal';
Expand Down Expand Up @@ -93,7 +94,7 @@ class Add extends ContractModal<Props, State> {

this.setState({ isBusy: true }, (): void => {
store
.saveCode(createType('Hash', codeHash), { abi, name, tags })
.saveCode(createType(registry, 'Hash', codeHash), { abi, name, tags })
.then((): void => {
this.setState(
{ isBusy: false },
Expand Down
6 changes: 3 additions & 3 deletions packages/app-contracts/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { CodeJson, CodeStored } from './types';
import EventEmitter from 'eventemitter3';
import store from 'store';
import { Abi } from '@polkadot/api-contract';
import { api, registry } from '@polkadot/react-api';
import { createType } from '@polkadot/types';
import { api } from '@polkadot/react-api';

const KEY_CODE = 'code:';

Expand All @@ -30,7 +30,7 @@ class Store extends EventEmitter {

// eslint-disable-next-line @typescript-eslint/require-await
public async saveCode (codeHash: string | Hash, partial: Partial<CodeJson>): Promise<void> {
const hex = (typeof codeHash === 'string' ? createType('Hash', codeHash) : codeHash).toHex();
const hex = (typeof codeHash === 'string' ? createType(registry, 'Hash', codeHash) : codeHash).toHex();

const existing = this.getCode(hex);

Expand Down Expand Up @@ -78,7 +78,7 @@ class Store extends EventEmitter {
this.allCode[json.codeHash] = {
json,
contractAbi: abi
? new Abi(abi)
? new Abi(registry, abi)
: undefined
};

Expand Down
6 changes: 3 additions & 3 deletions packages/app-council/src/Motions/Propose.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { Call, Proposal } from '@polkadot/types/interfaces';

import BN from 'bn.js';
import React from 'react';
import { createType } from '@polkadot/types';
import { withCalls, withMulti, registry } from '@polkadot/react-api';
import { Button, Extrinsic, InputNumber } from '@polkadot/react-components';
import TxModal, { TxModalState, TxModalProps } from '@polkadot/react-components/TxModal';
import { withCalls, withMulti } from '@polkadot/react-api';
import { createType } from '@polkadot/types';

import translate from '../translate';

Expand Down Expand Up @@ -54,7 +54,7 @@ class Propose extends TxModal<Props, State> {

return [
threshold,
...(method ? [createType('Proposal', method)] : [])
...(method ? [createType(registry, 'Proposal', method)] : [])
];
}

Expand Down
4 changes: 2 additions & 2 deletions packages/app-council/src/Overview/Vote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import BN from 'bn.js';
import React from 'react';
import styled from 'styled-components';
import { createType } from '@polkadot/types';
import { withCalls, withMulti } from '@polkadot/react-api';
import { registry, withCalls, withMulti } from '@polkadot/react-api';
import { AddressMini, Button, Toggle } from '@polkadot/react-components';
import TxModal, { TxModalState, TxModalProps } from '@polkadot/react-components/TxModal';

Expand Down Expand Up @@ -141,7 +141,7 @@ class Vote extends TxModal<Props, State> {
approvals
? approvals.slice(0, 1 + approvals.lastIndexOf(true))
: [],
createType('VoteIndex', voteCount),
createType(registry, 'VoteIndex', voteCount),
voterPositions && accountId && voterPositions[accountId]
? voterPositions[accountId].setIndex
: nextVoterSet || null
Expand Down
8 changes: 4 additions & 4 deletions packages/app-council/src/Overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { BlockNumber } from '@polkadot/types/interfaces';
import { ComponentProps } from './types';

import React from 'react';
import { withCalls } from '@polkadot/react-api';
import { withCalls, registry } from '@polkadot/react-api';
import { Button } from '@polkadot/react-components';
import { createType } from '@polkadot/types';

Expand All @@ -22,11 +22,11 @@ interface Props extends ComponentProps {

const NULL_INFO: DerivedElectionsInfo = {
candidates: [],
candidateCount: createType('u32'),
desiredSeats: createType('u32'),
candidateCount: createType(registry, 'u32'),
desiredSeats: createType(registry, 'u32'),
members: [],
runnersUp: [],
termDuration: createType('BlockNumber')
termDuration: createType(registry, 'BlockNumber')
};

function Overview ({ bestNumber, electionsInfo = NULL_INFO }: Props): React.ReactElement<Props> {
Expand Down
4 changes: 2 additions & 2 deletions packages/app-democracy/src/Overview/Propose.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React from 'react';
import { createType } from '@polkadot/types';
import { Button, Extrinsic, InputBalance } from '@polkadot/react-components';
import TxModal, { TxModalState, TxModalProps } from '@polkadot/react-components/TxModal';
import { withApi, withMulti } from '@polkadot/react-api';
import { registry, withApi, withMulti } from '@polkadot/react-api';

import translate from '../translate';

Expand All @@ -36,7 +36,7 @@ class Propose extends TxModal<Props, State> {
protected txParams = (): [Call, BN] => {
const { value, method } = this.state;

return [createType('Proposal', method || undefined), value];
return [createType(registry, 'Proposal', method || undefined), value];
}

protected isDisabled = (): boolean => {
Expand Down
4 changes: 2 additions & 2 deletions packages/app-explorer/src/BlockInfo/Extrinsics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { I18nProps } from '@polkadot/react-components/types';

import React from 'react';
import styled from 'styled-components';
import { GenericCall } from '@polkadot/types';
import { registry } from '@polkadot/react-api';
import { AddressMini, Call, Column, LinkPolkascan } from '@polkadot/react-components';
import { formatNumber } from '@polkadot/util';

Expand Down Expand Up @@ -41,7 +41,7 @@ function renderExtrinsic (props: Props): (_: Extrinsic, __: number) => React.Rea
const { blockNumber, t } = props;

return function ExplorerExtrinsic (extrinsic: Extrinsic, index: number): React.ReactNode {
const { meta, method, section } = GenericCall.findFunction(extrinsic.callIndex);
const { meta, method, section } = registry.findMetaCall(extrinsic.callIndex);
const isMortal = extrinsic.era.isMortalEra;
let eraEnd;
let eraStart;
Expand Down
4 changes: 2 additions & 2 deletions packages/app-settings/src/Developer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AppProps, I18nProps } from '@polkadot/react-components/types';
import React, { useEffect, useState } from 'react';
import store from 'store';
import styled from 'styled-components';
import { getTypeRegistry } from '@polkadot/types';
import { registry } from '@polkadot/react-api';
import { Button, Editor, InputFile } from '@polkadot/react-components';
import { isJsonObject, stringToU8a, u8aToString } from '@polkadot/util';

Expand Down Expand Up @@ -96,7 +96,7 @@ function Developer ({ className, onStatusChange, t }: Props): React.ReactElement
};
const _saveDeveloper = (): void => {
try {
getTypeRegistry().register(types);
registry.register(types);
store.set('types', types);
setIsTypesValid(true);
onStatusChange({
Expand Down
25 changes: 15 additions & 10 deletions packages/app-staking/src/useSessionRewards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Slash, SessionRewards } from '@polkadot/react-hooks/types';
import BN from 'bn.js';
import { useEffect, useState } from 'react';
import { ApiPromise } from '@polkadot/api';
import { registry } from '@polkadot/react-api';
import { useApi, useCacheKey } from '@polkadot/react-hooks';
import { createType } from '@polkadot/types';
import { bnMax, u8aToU8a } from '@polkadot/util';
Expand All @@ -28,14 +29,14 @@ interface Serialized {

function fromJSON (sessions: Serialized[]): SessionRewards[] {
return sessions.map(({ blockHash, blockNumber, isEventsEmpty, reward, sessionIndex, slashes }): SessionRewards => ({
blockHash: createType('Hash', blockHash),
blockNumber: createType('BlockNumber', blockNumber),
blockHash: createType(registry, 'Hash', blockHash),
blockNumber: createType(registry, 'BlockNumber', blockNumber),
isEventsEmpty,
reward: createType('Balance', reward),
sessionIndex: createType('SessionIndex', sessionIndex),
reward: createType(registry, 'Balance', reward),
sessionIndex: createType(registry, 'SessionIndex', sessionIndex),
slashes: slashes.map(({ accountId, amount }): Slash => ({
accountId: createType('AccountId', accountId),
amount: createType('Balance', amount)
accountId: createType(registry, 'AccountId', accountId),
amount: createType(registry, 'Balance', amount)
}))
}));
}
Expand Down Expand Up @@ -104,8 +105,8 @@ async function loadSome (api: ApiPromise, fromHash: Hash, toHash: Hash): Promise
blockHash: headers[index].hash,
blockNumber: headers[index].number.unwrap(),
isEventsEmpty: events[index].length === 0,
reward: rewards[index] || createType('Balance'),
sessionIndex: createType('SessionIndex', u8aToU8a(
reward: rewards[index] || createType(registry, 'Balance'),
sessionIndex: createType(registry, 'SessionIndex', u8aToU8a(
value.isSome ? value.unwrap() : new Uint8Array([])
)),
slashes: slashes[index]
Expand All @@ -124,8 +125,10 @@ export default function useSessionRewards (maxSessions: number): SessionRewards[
api.isReady.then(async (): Promise<void> => {
const maxSessionsStore = maxSessions + 1; // assuming first is a bust
const sessionLength = api.consts.babe?.epochDuration || new BN(500);
const count = Math.min(sessionLength.muln(maxSessionsStore).divn(10).toNumber(), 10000);
const eraLength = api.consts.staking.sessionsPerEra.toNumber();
const count = Math.min(sessionLength.muln(maxSessionsStore).divn(10).toNumber(), 7500);
const bestHeader = await api.rpc.chain.getHeader();
let retrieved = 0;
let toHash = bestHeader.hash;
let toNumber = bestHeader.number.unwrap().toBn();
let fromHash = api.genesisHash;
Expand All @@ -136,6 +139,7 @@ export default function useSessionRewards (maxSessions: number): SessionRewards[

const newQueue = await loadSome(api, fromHash, toHash);

retrieved += newQueue.length;
workQueue = mergeResults(workQueue, newQueue);
toHash = fromHash;
toNumber = fromNumber;
Expand All @@ -146,7 +150,8 @@ export default function useSessionRewards (maxSessions: number): SessionRewards[

const lastNumber = workQueue[workQueue.length - 1]?.blockNumber;

if (!lastNumber || fromNumber.eqn(1) || ((workQueue.length >= maxSessionsStore) && fromNumber.lt(lastNumber))) {
// we always want to retrieve at least 1 era worth of information, or we are at the start
if (!lastNumber || fromNumber.eqn(1) || (retrieved > eraLength && (workQueue.length >= maxSessionsStore) && fromNumber.lt(lastNumber))) {
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/app-sudo/src/Sudo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ComponentProps } from './types';
import React from 'react';
import { createType } from '@polkadot/types';
import { Button, Icon, Extrinsic, TxButton, TxComponent } from '@polkadot/react-components';
import { withApi, withMulti } from '@polkadot/react-api';
import { registry, withApi, withMulti } from '@polkadot/react-api';

import translate from './translate';

Expand Down Expand Up @@ -50,7 +50,7 @@ class Propose extends TxComponent<Props, State> {
icon='sign-in'
tx='sudo.sudo'
isDisabled={!method || !isValid}
params={method ? [createType('Proposal', method)] : []}
params={method ? [createType(registry, 'Proposal', method)] : []}
ref={this.button}
/>
</Button.Group>
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@babel/runtime": "^7.7.2",
"@polkadot/react-components": "^0.37.0-beta.109",
"@polkadot/react-signer": "^0.37.0-beta.109",
"@polkadot/ui-assets": "^0.47.0-beta.6",
"@polkadot/ui-assets": "^0.47.0-beta.7",
"query-string": "^6.8.3"
}
}
5 changes: 2 additions & 3 deletions packages/apps/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import ReactDOM from 'react-dom';
import { HashRouter } from 'react-router-dom';
import store from 'store';
import { ThemeProvider } from 'styled-components';
import { getTypeRegistry } from '@polkadot/types';
import { Api } from '@polkadot/react-api';
import { Api, registry } from '@polkadot/react-api';
import { QueueConsumer } from '@polkadot/react-components/Status/Context';
import Queue from '@polkadot/react-components/Status/Queue';
import { BlockAuthors, Events } from '@polkadot/react-query';
Expand Down Expand Up @@ -46,7 +45,7 @@ try {
const names = Object.keys(types);

if (names.length) {
getTypeRegistry().register(types);
registry.register(types);
console.log('Type registration:', names.join(', '));
}
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"homepage": "https://github.com/polkadot-js/ui/tree/master/packages/ui-reactive#readme",
"dependencies": {
"@babel/runtime": "^7.7.2",
"@polkadot/api": "^0.97.0-beta.16",
"@polkadot/api": "^0.97.0-beta.19",
"@polkadot/extension-dapp": "^0.14.0-beta.5",
"edgeware-node-types": "^1.0.10",
"rxjs-compat": "^6.5.3"
Expand Down
6 changes: 4 additions & 2 deletions packages/react-api/src/Api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import addressDefaults from '@polkadot/util-crypto/address/defaults';
import typesChain from './overrides/chain';
import typesSpec from './overrides/spec';
import ApiContext from './ApiContext';
import registry from './typeRegistry';

interface Props {
children: React.ReactNode;
Expand All @@ -42,8 +43,8 @@ interface InjectedAccountExt {
};
}

const DEFAULT_DECIMALS = new U32(12);
const DEFAULT_SS58 = new U32(addressDefaults.prefix);
const DEFAULT_DECIMALS = new U32(registry, 12);
const DEFAULT_SS58 = new U32(registry, addressDefaults.prefix);

const injectedPromise = web3Enable('polkadot-js/apps');
let api: ApiPromise;
Expand Down Expand Up @@ -85,6 +86,7 @@ export default class Api extends React.PureComponent<Props, State> {
private createApi (provider: ProviderInterface, signer: ApiSigner): ApiPromise {
return new ApiPromise({
provider,
registry,
signer,
typesChain,
typesSpec
Expand Down
4 changes: 3 additions & 1 deletion packages/react-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

import Api, { api } from './Api';
import ApiContext from './ApiContext';
import registry from './typeRegistry';

export * from './ledger';
export * from './with';

export {
api,
Api,
ApiContext
ApiContext,
registry
};
Loading