withAccount.js 885 B
Newer Older
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
Axel Chalon's avatar
Axel Chalon committed
// This file is part of Parity.
//
// SPDX-License-Identifier: BSD-3-Clause

import { withRouter } from 'react-router-dom';
import { compose, mapProps } from 'recompose';

import withAccountsInfo from '../utils/withAccountsInfo';
Axel Chalon's avatar
Axel Chalon committed

Axel Chalon's avatar
Axel Chalon committed
const WithAccount = compose(
  withRouter,
  withAccountsInfo,
  mapProps(
    ({
Axel Chalon's avatar
Axel Chalon committed
      match: {
        params: { accountAddress }
      },
Axel Chalon's avatar
Axel Chalon committed
      accountsInfo,
      ...otherProps
    }) => ({
      account: {
        address: accountAddress,
        name: accountsInfo[accountAddress].name,
        type: accountsInfo[accountAddress].type
Axel Chalon's avatar
Axel Chalon committed
      },
      ...otherProps
    })
  )
)(props => props.children(props.account));
Axel Chalon's avatar
Axel Chalon committed
export default Component => initialProps => (
  <WithAccount>
    {account => <Component {...initialProps} account={account} />}
  </WithAccount>
);