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

Axel Chalon's avatar
Axel Chalon committed

// Shape of the default value needs to match the shape that the consumers expect
export const AccountContext = React.createContext({
  accountAddress: null
});

export const consumeAccount = Component => props => (
  <AccountContext.Consumer>
    {contextValues => {
      console.log("consumer function, contextvalues:", contextValues);
      return <Component {...contextValues} />;
    }}
  </AccountContext.Consumer>
);
Axel Chalon's avatar
Axel Chalon committed

export const provideAccount = getAccountAddress => Component => props => {
  console.log("provider get account address returns", getAccountAddress(props));
Axel Chalon's avatar
Axel Chalon committed
  return (
    <AccountContext.Provider
      value={{ accountAddress: getAccountAddress(props) }}
    >
Axel Chalon's avatar
Axel Chalon committed
      <Component {...props} />
Axel Chalon's avatar
Axel Chalon committed
  );
};