Browse Source

Adjust staking (#1914)

* Adjust staking

* Bump deps
Jaco Greeff 5 years ago
parent
commit
19162076f6

+ 2 - 2
README.md

@@ -37,7 +37,7 @@ In addition the following libraries are also included in the repo. These are to
 
 Contributions are welcome!
 
-To start off, this repo (along with others in the [@polkadot](https://github.com/polkadot-js/) family) uses yarn workspaces to organise the code. As such, after cloning dependencies _should_ be installed via `yarn`, not via npm, the latter will result in broken dependencies.
+To start off, this repo (along with others in the [@polkadot](https://github.com/polkadot-js/) family) uses yarn workspaces to organize the code. As such, after cloning dependencies _should_ be installed via `yarn`, not via npm, the latter will result in broken dependencies.
 
 To get started -
 
@@ -50,7 +50,7 @@ To get started -
 
 ## I want to code around
 
-There is a base template availble [app-123code](packages/app-123code/) that acts as a simple starting point for adding additional apps to the UI. Alternatively if you just want some place where you can write some code, it does the trick.
+There is a base template available [app-123code](packages/app-123code/) that acts as a simple starting point for adding additional apps to the UI. Alternatively if you just want some place where you can write some code, it does the trick.
 
 While it is hidden from the sidebar, it is accessible via [http://127.0.0.1:3000/#/123code](http://127.0.0.1:3000/#/123code)
 

+ 3 - 3
package.json

@@ -10,10 +10,10 @@
     "packages/*"
   ],
   "resolutions": {
-    "@polkadot/api": "^0.97.0-beta.13",
-    "@polkadot/api-contract": "^0.97.0-beta.13",
+    "@polkadot/api": "^0.97.0-beta.14",
+    "@polkadot/api-contract": "^0.97.0-beta.14",
     "@polkadot/keyring": "^1.7.0-beta.7",
-    "@polkadot/types": "^0.97.0-beta.13",
+    "@polkadot/types": "^0.97.0-beta.14",
     "@polkadot/util": "^1.7.0-beta.7",
     "@polkadot/util-crypto": "^1.7.0-beta.7",
     "babel-core": "^7.0.0-bridge.0",

+ 1 - 1
packages/app-contracts/package.json

@@ -11,7 +11,7 @@
   "license": "Apache-2.0",
   "dependencies": {
     "@babel/runtime": "^7.7.2",
-    "@polkadot/api-contract": "^0.97.0-beta.13",
+    "@polkadot/api-contract": "^0.97.0-beta.14",
     "@polkadot/react-components": "^0.37.0-beta.105"
   }
 }

+ 27 - 31
packages/app-staking/src/Actions/Account/index.tsx

@@ -26,13 +26,13 @@ import Validate from './Validate';
 import { u8aToHex, u8aConcat } from '@polkadot/util';
 
 interface Props extends ApiProps, I18nProps {
-  accountId: string;
   allStashes?: string[];
   balances_all?: DerivedBalances;
   className?: string;
-  ownStash: boolean;
+  isOwnStash: boolean;
   recentlyOnline?: DerivedHeartbeats;
   staking_info?: DerivedStaking;
+  stashId: string;
   stashOptions: KeyringSectionOption[];
 }
 
@@ -57,7 +57,6 @@ interface State {
   sessionIds: string[];
   stakers?: Exposure;
   stakingLedger?: StakingLedger;
-  stashId: string | null;
   validatorPrefs?: ValidatorPrefs;
 }
 
@@ -101,19 +100,17 @@ class Account extends React.PureComponent<Props, State> {
     isUnbondOpen: false,
     isValidateOpen: false,
     onlineStatus: {},
-    sessionIds: [],
-    stashId: null
+    sessionIds: []
   };
 
-  public static getDerivedStateFromProps ({ allStashes, staking_info }: Props): Pick<State, never> | null {
+  public static getDerivedStateFromProps ({ allStashes, staking_info, stashId }: Props): Pick<State, never> | null {
     if (!staking_info) {
       return null;
     }
 
-    const { controllerId, nextSessionIds, nominators, rewardDestination, sessionIds, stakers, stakingLedger, stashId, validatorPrefs } = staking_info;
+    const { controllerId, nextSessionIds, nominators, rewardDestination, sessionIds, stakers, stakingLedger, validatorPrefs } = staking_info;
     const isStashNominating = nominators && !!nominators.length;
-    const _stashId = toIdString(stashId);
-    const isStashValidating = !!allStashes && !!_stashId && allStashes.includes(_stashId);
+    const isStashValidating = !!allStashes && !!stashId && allStashes.includes(stashId);
     const nextConcat = u8aConcat(...nextSessionIds.map((id): Uint8Array => id.toU8a()));
     const currConcat = u8aConcat(...sessionIds.map((id): Uint8Array => id.toU8a()));
 
@@ -132,18 +129,13 @@ class Account extends React.PureComponent<Props, State> {
       ).map(toIdString),
       stakers,
       stakingLedger,
-      stashId: _stashId,
       validatorPrefs
     };
   }
 
   public render (): React.ReactNode {
-    const { className, isSubstrateV2, t } = this.props;
-    const { controllerId, hexSessionIdNext, hexSessionIdQueue, isBondExtraOpen, isInjectOpen, isStashValidating, isUnbondOpen, nominees, onlineStatus, sessionIds, stashId } = this.state;
-
-    if (!stashId) {
-      return null;
-    }
+    const { className, isSubstrateV2, stashId, t } = this.props;
+    const { controllerId, hexSessionIdNext, hexSessionIdQueue, isBondExtraOpen, isInjectOpen, isStashValidating, isUnbondOpen, nominees, onlineStatus, sessionIds } = this.state;
 
     // Each component is rendered and gets a `is[Component]Open` passed in a `isOpen` props.
     // These components will be loaded and return null at the first load (because is[Component]Open === false).
@@ -250,8 +242,8 @@ class Account extends React.PureComponent<Props, State> {
   }
 
   private renderNominate (): React.ReactNode {
-    const { stashOptions } = this.props;
-    const { controllerId, isNominateOpen, nominees, stashId } = this.state;
+    const { stashId, stashOptions } = this.props;
+    const { controllerId, isNominateOpen, nominees } = this.state;
 
     if (!isNominateOpen || !stashId || !controllerId) {
       return null;
@@ -269,9 +261,10 @@ class Account extends React.PureComponent<Props, State> {
   }
 
   private renderValidate (): React.ReactNode {
-    const { controllerId, isValidateOpen, stashId, validatorPrefs } = this.state;
+    const { stashId } = this.props;
+    const { controllerId, isValidateOpen, validatorPrefs } = this.state;
 
-    if (!stashId || !controllerId) {
+    if (!controllerId) {
       return null;
     }
 
@@ -370,7 +363,7 @@ class Account extends React.PureComponent<Props, State> {
   }
 
   private renderPopupMenu (): React.ReactNode {
-    const { balances_all, isSubstrateV2, ownStash, t } = this.props;
+    const { balances_all, isOwnStash, isSubstrateV2, t } = this.props;
     const { hexSessionIdNext, isStashNominating, isStashValidating, sessionIds } = this.state;
 
     // only show a "Bond Additional" button if this stash account actually doesn't bond everything already
@@ -385,7 +378,7 @@ class Account extends React.PureComponent<Props, State> {
       >
         {canBondExtra &&
           <Menu.Item
-            disabled={!ownStash}
+            disabled={!isOwnStash}
             onClick={this.toggleBondExtra}
           >
             {t('Bond more funds')}
@@ -395,7 +388,7 @@ class Account extends React.PureComponent<Props, State> {
           {t('Unbond funds')}
         </Menu.Item>
         <Menu.Item
-          disabled={!ownStash}
+          disabled={!isOwnStash}
           onClick={this.toggleSetControllerAccount}
         >
           {t('Change controller account')}
@@ -428,9 +421,10 @@ class Account extends React.PureComponent<Props, State> {
   }
 
   private renderSetValidatorPrefs (): React.ReactNode {
-    const { controllerId, isValidateOpen, stashId, validatorPrefs } = this.state;
+    const { stashId } = this.props;
+    const { controllerId, isValidateOpen, validatorPrefs } = this.state;
 
-    if (!controllerId || !validatorPrefs || !stashId) {
+    if (!controllerId || !validatorPrefs) {
       return null;
     }
 
@@ -446,9 +440,10 @@ class Account extends React.PureComponent<Props, State> {
   }
 
   private renderSetControllerAccount (): React.ReactNode {
-    const { controllerId, isSetControllerAccountOpen, isStashValidating, stashId } = this.state;
+    const { stashId } = this.props;
+    const { controllerId, isSetControllerAccountOpen, isStashValidating } = this.state;
 
-    if (!isSetControllerAccountOpen || !stashId) {
+    if (!isSetControllerAccountOpen) {
       return null;
     }
 
@@ -479,9 +474,10 @@ class Account extends React.PureComponent<Props, State> {
   }
 
   private renderSetSessionAccount (): React.ReactNode {
-    const { controllerId, isSetSessionAccountOpen, stashId, sessionIds } = this.state;
+    const { stashId } = this.props;
+    const { controllerId, isSetSessionAccountOpen, sessionIds } = this.state;
 
-    if (!controllerId || !stashId) {
+    if (!controllerId) {
       return null;
     }
 
@@ -623,7 +619,7 @@ export default withMulti(
   `,
   translate,
   withCalls<Props>(
-    ['derive.staking.info', { paramName: 'accountId' }],
-    ['derive.balances.all', { paramName: 'accountId' }]
+    ['derive.staking.info', { paramName: 'stashId' }],
+    ['derive.balances.all', { paramName: 'stashId' }]
   )
 );

+ 6 - 6
packages/app-staking/src/Actions/Accounts.tsx → packages/app-staking/src/Actions/index.tsx

@@ -44,7 +44,7 @@ function getStashes (allAccounts: string[], queryBonded?: Option<AccountId>[], q
   return result;
 }
 
-function Accounts ({ allAccounts, allStashes, className, recentlyOnline, t }: Props): React.ReactElement<Props> {
+function Actions ({ allAccounts, allStashes, className, recentlyOnline, t }: Props): React.ReactElement<Props> {
   const { api } = useApi();
   const queryBonded = trackStream<Option<AccountId>[]>(api.query.staking.bonded.multi as any, [allAccounts]);
   const queryLedger = trackStream<Option<StakingLedger>[]>(api.query.staking.ledger.multi as any, [allAccounts]);
@@ -75,14 +75,14 @@ function Accounts ({ allAccounts, allStashes, className, recentlyOnline, t }: Pr
       {isNewStakeOpen && (
         <StartStaking onClose={_toggleNewStake} />
       )}
-      {foundStashes && foundStashes.map(([address, ownStash], index): React.ReactNode => (
-        address && (
+      {foundStashes && foundStashes.map(([stashId, isOwnStash], index): React.ReactNode => (
+        stashId && (
           <Account
             allStashes={allStashes}
-            accountId={address}
+            isOwnStash={isOwnStash}
             key={index}
-            ownStash={ownStash}
             recentlyOnline={recentlyOnline}
+            stashId={stashId}
             stashOptions={stashOptions}
           />
         )
@@ -92,7 +92,7 @@ function Accounts ({ allAccounts, allStashes, className, recentlyOnline, t }: Pr
 }
 
 export default translate(
-  styled(Accounts)`
+  styled(Actions)`
     .ui--CardGrid-buttons {
       text-align: right;
     }

+ 2 - 2
packages/app-staking/src/index.tsx

@@ -16,7 +16,7 @@ import { HelpOverlay } from '@polkadot/react-components';
 import Tabs from '@polkadot/react-components/Tabs';
 import { trackStream, useAccounts, useApi } from '@polkadot/react-hooks';
 
-import Accounts from './Actions/Accounts';
+import Actions from './Actions';
 import basicMd from './md/basic.md';
 import Overview from './Overview';
 import Query from './Query';
@@ -98,7 +98,7 @@ function App ({ basePath, className, t }: Props): React.ReactElement<Props> {
         />
       </header>
       <Switch>
-        <Route path={`${basePath}/actions`}>{_renderComponent(Accounts)}</Route>
+        <Route path={`${basePath}/actions`}>{_renderComponent(Actions)}</Route>
         <Route path={`${basePath}/query/:value`}>{_renderComponent(Query)}</Route>
         <Route path={`${basePath}/query`}>{_renderComponent(Query)}</Route>
       </Switch>

+ 1 - 1
packages/react-api/package.json

@@ -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.13",
+    "@polkadot/api": "^0.97.0-beta.14",
     "@polkadot/extension-dapp": "^0.14.0-beta.5",
     "edgeware-node-types": "^1.0.10",
     "rxjs-compat": "^6.5.3"

+ 45 - 45
yarn.lock

@@ -2029,35 +2029,35 @@
   dependencies:
     "@types/node" ">= 8"
 
-"@polkadot/api-contract@^0.97.0-beta.13":
-  version "0.97.0-beta.13"
-  resolved "https://registry.yarnpkg.com/@polkadot/api-contract/-/api-contract-0.97.0-beta.13.tgz#f91c56289c84b2dce9e71360e6e0705a6f8e94bd"
-  integrity sha512-SwDmh6lGZm9H5rbfEShVt48j4Y1nrE9xyDQDLyfe6SbgKxgw0AkeuDVHM0W2xNX0t0hKHoAaPZ3E4M1/rxtPYA==
+"@polkadot/api-contract@^0.97.0-beta.14":
+  version "0.97.0-beta.14"
+  resolved "https://registry.yarnpkg.com/@polkadot/api-contract/-/api-contract-0.97.0-beta.14.tgz#9cfd712d0f033f0055f06559c19b43463632de64"
+  integrity sha512-5njEMQG9XB3aJWgzmZ5DcFLg3IpbkF27taYfO3g3KCjv2Guw3yIhQ1JYsh+py2LvLe1ob0EaA7/CdS+Y4B2X6Q==
   dependencies:
     "@babel/runtime" "^7.7.2"
-    "@polkadot/types" "^0.97.0-beta.13"
+    "@polkadot/types" "^0.97.0-beta.14"
 
-"@polkadot/api-derive@^0.97.0-beta.13":
-  version "0.97.0-beta.13"
-  resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-0.97.0-beta.13.tgz#dc53fe75a28b4d13ff3bcab6495f97ff382896c7"
-  integrity sha512-+IVzqLOOqJT6SXFqrCrYFL85rWnFDuc4SD1e0UtcQvGsBwvX4EMLoPuwxz0kI3fB0wu+sehfeGntaluYT0ZQ/g==
+"@polkadot/api-derive@^0.97.0-beta.14":
+  version "0.97.0-beta.14"
+  resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-0.97.0-beta.14.tgz#1c327158c466a7d1d37f9d9cf7db32a00a501d53"
+  integrity sha512-XDOcvXI6b3QGtqJX6CV3BKrel8zkikVenS2VozhjrwlU2upIxqW6ImSPXsgZl1nhpYfDkClFATo/44KuPDzRwQ==
   dependencies:
     "@babel/runtime" "^7.7.2"
-    "@polkadot/api" "^0.97.0-beta.13"
-    "@polkadot/types" "^0.97.0-beta.13"
+    "@polkadot/api" "^0.97.0-beta.14"
+    "@polkadot/types" "^0.97.0-beta.14"
 
-"@polkadot/api@^0.97.0-beta.13":
-  version "0.97.0-beta.13"
-  resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.97.0-beta.13.tgz#535522ee08d51d1ca28eeeba7ce25236597ea9a7"
-  integrity sha512-60e84c/4SbxGney23wi9siKzb7xJxekHsOS4+TO83sqPf5LJB+fbiC6AHFuzv3uPcIY66Fv/yQuWX8eZex2M3g==
+"@polkadot/api@^0.97.0-beta.14":
+  version "0.97.0-beta.14"
+  resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.97.0-beta.14.tgz#aecccb175aa8b33b92464a63c0e6b087f00673a3"
+  integrity sha512-SpoItbmFlJMWtVQQvvBiQ3bb23kzwdPOnIE5Hnl7bqSdzCnor0JXLtH06Zb7Myh1WsGzOekNt6QwH5DwrLiAIQ==
   dependencies:
     "@babel/runtime" "^7.7.2"
-    "@polkadot/api-derive" "^0.97.0-beta.13"
+    "@polkadot/api-derive" "^0.97.0-beta.14"
     "@polkadot/keyring" "^1.7.0-beta.7"
-    "@polkadot/metadata" "^0.97.0-beta.13"
-    "@polkadot/rpc-core" "^0.97.0-beta.13"
-    "@polkadot/rpc-provider" "^0.97.0-beta.13"
-    "@polkadot/types" "^0.97.0-beta.13"
+    "@polkadot/metadata" "^0.97.0-beta.14"
+    "@polkadot/rpc-core" "^0.97.0-beta.14"
+    "@polkadot/rpc-provider" "^0.97.0-beta.14"
+    "@polkadot/types" "^0.97.0-beta.14"
     "@polkadot/util-crypto" "^1.7.0-beta.7"
 
 "@polkadot/dev-react@^0.32.0-beta.14":
@@ -2160,10 +2160,10 @@
   dependencies:
     "@babel/runtime" "^7.7.2"
 
-"@polkadot/jsonrpc@^0.97.0-beta.13":
-  version "0.97.0-beta.13"
-  resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.97.0-beta.13.tgz#6e285d7c8d9623c89e1075af581034dd0298c75f"
-  integrity sha512-ydBmkF0nxU8roaiNXIQ8TyBhrrvtmk50xuSMwJ9645c6gIV0EUhmtQYng/mbgu3s6a1AIeQ/34oY18A5vTOh4w==
+"@polkadot/jsonrpc@^0.97.0-beta.14":
+  version "0.97.0-beta.14"
+  resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.97.0-beta.14.tgz#9e51fb90e70ff6180d0d2c270cdfe8618c179aa9"
+  integrity sha512-stZrbZLQfNveI5zrjJb+ksoNkCB5kbfnxElKg3ZoiNxCCFOBkOXzejHwxcstNa140I3G6gfmMQauGdRuXHsLAg==
   dependencies:
     "@babel/runtime" "^7.7.2"
 
@@ -2176,13 +2176,13 @@
     "@polkadot/util" "^1.7.0-beta.7"
     "@polkadot/util-crypto" "^1.7.0-beta.7"
 
-"@polkadot/metadata@^0.97.0-beta.13":
-  version "0.97.0-beta.13"
-  resolved "https://registry.yarnpkg.com/@polkadot/metadata/-/metadata-0.97.0-beta.13.tgz#004bd45ba8b215e5cd48a8cac90b0f39aabc6adf"
-  integrity sha512-qerBZ9UB4lFLYA3HJfjsFwJzjOS8MNb4Pqc6YFSPUqzkmYrVeBT3kQFvfWY1kdu3forIg9DDi/togTlFvyVB2g==
+"@polkadot/metadata@^0.97.0-beta.14":
+  version "0.97.0-beta.14"
+  resolved "https://registry.yarnpkg.com/@polkadot/metadata/-/metadata-0.97.0-beta.14.tgz#3354455d09adf3009d1e16ca324a2e6a95542330"
+  integrity sha512-uPq/rvw4BD1lXZWNr3Wt4gb+lIfNZjfVRm97Y0xVKdPhabKDK54NP5kNnW1zVS6W8p7q1kbYYTPHQkJ3Ok6qFA==
   dependencies:
     "@babel/runtime" "^7.7.2"
-    "@polkadot/types" "^0.97.0-beta.13"
+    "@polkadot/types" "^0.97.0-beta.14"
     "@polkadot/util" "^1.7.0-beta.7"
     "@polkadot/util-crypto" "^1.7.0-beta.7"
 
@@ -2211,25 +2211,25 @@
     qrcode-generator "^1.4.4"
     react-qr-reader "^2.2.1"
 
-"@polkadot/rpc-core@^0.97.0-beta.13":
-  version "0.97.0-beta.13"
-  resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-0.97.0-beta.13.tgz#535a2895fa2daf0db630e0906c2ce10b665b8964"
-  integrity sha512-1V0O9y1suCI+idbuilWYqTOTbhQuuqquno1gCniGzFnZEqb3HHr9tvafuv9TKa0LEFlESQqvj/aO52hoyHxb9A==
+"@polkadot/rpc-core@^0.97.0-beta.14":
+  version "0.97.0-beta.14"
+  resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-0.97.0-beta.14.tgz#39ac304a580b7e22a63929e17b377d3098ac8635"
+  integrity sha512-Q/LmYhVVF+4CcAydcpqpO4aioXX4xkIhNTs9l+KtnPnJri7G1oTELS/uvZp/+3oRYIhvW5Vj2y9KZIAqqi+82A==
   dependencies:
     "@babel/runtime" "^7.7.2"
-    "@polkadot/jsonrpc" "^0.97.0-beta.13"
-    "@polkadot/rpc-provider" "^0.97.0-beta.13"
-    "@polkadot/types" "^0.97.0-beta.13"
+    "@polkadot/jsonrpc" "^0.97.0-beta.14"
+    "@polkadot/rpc-provider" "^0.97.0-beta.14"
+    "@polkadot/types" "^0.97.0-beta.14"
     "@polkadot/util" "^1.7.0-beta.7"
     rxjs "^6.5.3"
 
-"@polkadot/rpc-provider@^0.97.0-beta.13":
-  version "0.97.0-beta.13"
-  resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-0.97.0-beta.13.tgz#c74719e349829bdc8895a76dbcc37d2cb871224b"
-  integrity sha512-3hvFRXOfl9YZOfXsqc9bkKGIRfApF9cRwxfqsbMJkGv44BHml+lh7+8wkQrW2PTEwOsPSqjFjAYFPyYiVZCCtg==
+"@polkadot/rpc-provider@^0.97.0-beta.14":
+  version "0.97.0-beta.14"
+  resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-0.97.0-beta.14.tgz#3f5b94cc1d7be8a5d7416eb043944e41f6fc58a8"
+  integrity sha512-Tu2Pn2PoZN9A9xQZbo6dQvafLg07gUGjnbGQdWxPKKtKdZZEXfgcau2VyAMCNOD1zxRAczQVadlx7uJnWUqM1A==
   dependencies:
     "@babel/runtime" "^7.7.2"
-    "@polkadot/metadata" "^0.97.0-beta.13"
+    "@polkadot/metadata" "^0.97.0-beta.14"
     "@polkadot/util" "^1.7.0-beta.7"
     "@polkadot/util-crypto" "^1.7.0-beta.7"
     eventemitter3 "^4.0.0"
@@ -2243,10 +2243,10 @@
   dependencies:
     "@types/chrome" "^0.0.91"
 
-"@polkadot/types@^0.97.0-beta.13":
-  version "0.97.0-beta.13"
-  resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.97.0-beta.13.tgz#d5ffc8fde2408b2b75817f0efc0e5728fc49adcd"
-  integrity sha512-WKaco5Dfqg6ycxLQ6hvngR8vOAVsZiHWH9bhLXSqB7rqONiZ61u/e2sczyRBPKMuMvVT8vHQwUNTr6NSaQD+mQ==
+"@polkadot/types@^0.97.0-beta.14":
+  version "0.97.0-beta.14"
+  resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.97.0-beta.14.tgz#8c7db6e44b3edf757348c89b9bea133e12e73b93"
+  integrity sha512-/NIJ1lPfYw2dhFS3TiMkt3JCareuWvhOhO2Bs/+jKAMknBH9/EDJ7iAglbnaCWLLPIgQLd7r5nl3Ge2FyXZ0Ww==
   dependencies:
     "@babel/runtime" "^7.7.2"
     "@polkadot/util" "^1.7.0-beta.7"