Skip to content

Commit

Permalink
add getDistributionInfo action for enabling/disabling BEOS features i…
Browse files Browse the repository at this point in the history
…n the wallet
  • Loading branch information
Hayrullah Behar authored and aaroncox committed Jan 21, 2019
1 parent 0754dfd commit 6856d1d
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 21 deletions.
53 changes: 48 additions & 5 deletions app/shared/actions/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,60 @@ export function getInfo() {
dispatch({
type: types.GET_CHAIN_INFO_REQUEST
});
const { connection } = getState();
eos(connection).getInfo(true).then((chain) => dispatch({
type: types.GET_CHAIN_INFO_SUCCESS,
payload: { chain }
})).catch((err) => dispatch({
const { connection, chain: previousChain } = getState();

eos(connection).getInfo(true).then((chain) => {
/* Get distribution period info if we are in BEOS blockchain */
if (chain.chain_id === '50f1cee2e3750f473e673049c1b828ec10e10eb96c7211a91cc2bd29ae94c6dd') {
dispatch(getDistributionInfo());
} else if (previousChain && previousChain.hasOwnProperty('distributionPeriodInfo')) {
dispatch({ type: types.REMOVE_DISTRIBUTION_PERIOD_INFO })
}

return dispatch({
type: types.GET_CHAIN_INFO_SUCCESS,
payload: { chain }
})
}).catch((err) => dispatch({
type: types.GET_CHAIN_INFO_FAILURE,
payload: { err },
}));
};
}

/**
* Method to get distribution info
* Currently only for BEOS
*/
export function getDistributionInfo() {
return (dispatch: () => void, getState) => {
const { connection, chain: { head_block_num } } = getState();

const query = {
json: true,
code: 'beos.distrib',
scope: 'beos.distrib',
table: 'distribstate',
limit: 1000,
};

eos(connection).getTableRows(query).then(({ rows: [data] }) => {
dispatch({
type: types.GET_DISTRIBUTION_PERIOD_INFO,
payload: {
distributionPeriodInfo: {
ramDistribution: head_block_num < data['ram'].ending_block,
beosDistribution: head_block_num < data['beos'].ending_block
}
}
})
}).catch((err) => dispatch({
type: types.GET_DISTRIBUTION_PERIOD_INFO_FAILURE,
payload: { err }
}));
}
}

export default {
getInfo
};
3 changes: 3 additions & 0 deletions app/shared/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export const GET_CHAIN_INFO_SUCCESS = 'GET_CHAIN_INFO_SUCCESS';
export const GET_CURRENCYSTATS_FAILURE = 'GET_CURRENCYSTATS_FAILURE';
export const GET_CURRENCYSTATS_REQUEST = 'GET_CURRENCYSTATS_REQUEST';
export const GET_CURRENCYSTATS_SUCCESS = 'GET_CURRENCYSTATS_SUCCESS';
export const GET_DISTRIBUTION_PERIOD_INFO = 'GET_DISTRIBUTION_PERIOD_INFO';
export const GET_DISTRIBUTION_PERIOD_INFO_FAILURE = 'GET_DISTRIBUTION_PERIOD_INFO_FAILURE';
export const GET_PRODUCERS_FAILURE = 'GET_PRODUCERS_FAILURE';
export const GET_PRODUCERS_REQUEST = 'GET_PRODUCERS_REQUEST';
export const GET_PRODUCERS_SUCCESS = 'GET_PRODUCERS_SUCCESS';
Expand All @@ -44,6 +46,7 @@ export const IMPORT_WALLET_KEY = 'IMPORT_WALLET_KEY';
export const PREPARE_WALLET_CONVERT_LEDGER = 'PREPARE_WALLET_CONVERT_LEDGER';
export const PREPARE_WALLET_CONVERT_LEDGER_ABORT = 'PREPARE_WALLET_CONVERT_LEDGER_ABORT';
export const PREPARE_WALLET_CONVERT_LEDGER_COMPLETE = 'PREPARE_WALLET_CONVERT_LEDGER_COMPLETE';
export const REMOVE_DISTRIBUTION_PERIOD_INFO = 'REMOVE_DISTRIBUTION_PERIOD_INFO';
export const REMOVE_WALLET = 'REMOVE_WALLET';
export const RESET_ALL_STATES = 'RESET_ALL_STATES';
export const RESET_INVALID_SETTINGS = 'RESET_INVALID_SETTINGS';
Expand Down
1 change: 1 addition & 0 deletions app/shared/components/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default class Wallet extends Component<Props> {
balances={balances}
blockchains={blockchains}
blockExplorers={allBlockExplorers[connection.chainKey]}
chain={chain}
connection={connection}
globals={globals}
keys={keys}
Expand Down
2 changes: 2 additions & 0 deletions app/shared/components/Wallet/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default class WalletPanel extends Component<Props> {
balances,
blockchains,
blockExplorers,
chain,
connection,
globals,
keys,
Expand Down Expand Up @@ -49,6 +50,7 @@ export default class WalletPanel extends Component<Props> {
balances={balances}
blockchains={blockchains}
blockExplorers={blockExplorers}
chain={chain}
connection={connection}
globals={globals}
settings={settings}
Expand Down
25 changes: 13 additions & 12 deletions app/shared/components/Wallet/Panel/Unlocked.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class WalletPanelUnlocked extends Component<Props> {
balances,
blockchains,
blockExplorers,
chain,
connection,
globals,
validate,
Expand Down Expand Up @@ -64,10 +65,10 @@ class WalletPanelUnlocked extends Component<Props> {
active={activeIndex === 0}
>
<Segment.Group>
{(blockchain
&& blockchain.excludeFeatures
&& blockchain.excludeFeatures.includes('tokenstaking'))
? false
{(chain
&& chain.hasOwnProperty('distributionPeriodInfo')
&& chain.distributionPeriodInfo.beosDistribution) ?
false
: (
<Segment>
<WalletPanelButtonStake
Expand Down Expand Up @@ -98,10 +99,10 @@ class WalletPanelUnlocked extends Component<Props> {
accountName={settings.account}
/>
</Segment>
{(blockchain
&& blockchain.excludeFeatures
&& blockchain.excludeFeatures.includes('rambuy'))
? false
{(chain
&& chain.hasOwnProperty('distributionPeriodInfo')
&& chain.distributionPeriodInfo.ramDistribution) ?
false
: (
<Segment>
<WalletPanelButtonRamBuy
Expand All @@ -117,10 +118,10 @@ class WalletPanelUnlocked extends Component<Props> {
</Segment>
)
}
{(blockchain
&& blockchain.excludeFeatures
&& blockchain.excludeFeatures.includes('ramsell'))
? false
{(chain
&& chain.hasOwnProperty('distributionPeriodInfo')
&& chain.distributionPeriodInfo.ramDistribution) ?
false
: (
<Segment>
<WalletPanelButtonRamSell
Expand Down
3 changes: 2 additions & 1 deletion app/shared/containers/BasicVoter.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ type Props = {
wallet: {},
balances: {},
accounts: {},
system: {}
system: {},
chain: {}
};

class BasicVoterContainer extends Component<Props> {
Expand Down
14 changes: 11 additions & 3 deletions app/shared/containers/Tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,23 @@ class ToolsContainer extends Component<Props> {
t
} = this.props;
return paneMapping
.filter((pane) => {
const {
settings
.filter((pane) => {
const {
chain,
settings
} = this.props;
const {
skipImport,
walletMode,
walletTemp
} = settings;
/* Hide delegations pane in BEOS distrubition period */
if (pane.name === 'delegations' &&
chain.hasOwnProperty('distributionPeriodInfo') &&
chain.distributionPeriodInfo.beosDistribution) {
return false;
}

const paneRequiresContract = !!pane.requiredContract;
if (paneRequiresContract) {
if (connection.supportedContracts &&
Expand Down
1 change: 1 addition & 0 deletions app/shared/reducers/blockchains.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const knownChains = [
name: 'EOS',
node: 'https://eos.greymass.com',
supportedContracts: [
'crosschaintransfer',
'customtokens',
'producerinfo',
'proposals',
Expand Down
8 changes: 8 additions & 0 deletions app/shared/reducers/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ export default function chain(state = initialState, action) {
case types.GET_CHAIN_INFO_SUCCESS: {
return Object.assign({}, state, action.payload.chain);
}
case types.GET_DISTRIBUTION_PERIOD_INFO: {
return Object.assign({}, state, { ...action.payload })
}
case types.REMOVE_DISTRIBUTION_PERIOD_INFO: {
const newState = Object.assign({}, state);
delete newState.distributionPeriodInfo;
return newState;
}
default: {
return state;
}
Expand Down

0 comments on commit 6856d1d

Please sign in to comment.