Browse Source

Merge pull request #134 from SuperNETorg/same-coin-multiple-modes

Same coin multiple modes
all-modes
pbca26 8 years ago
committed by GitHub
parent
commit
854373a4fc
  1. 61
      react/src/components/addcoin/addcoin.js
  2. 2
      react/src/components/main/walletMain.js
  3. 10
      react/src/components/toaster/toaster-item.js
  4. 6
      react/src/translate/en.js

61
react/src/components/addcoin/addcoin.js

@ -38,6 +38,7 @@ class AddCoin extends React.Component {
actionsMenu: false, actionsMenu: false,
modalClassName: 'hide', modalClassName: 'hide',
}; };
this.existingCoins = null;
this.activateCoin = this.activateCoin.bind(this); this.activateCoin = this.activateCoin.bind(this);
this.dismiss = this.dismiss.bind(this); this.dismiss = this.dismiss.bind(this);
this.addNewItem = this.addNewItem.bind(this); this.addNewItem = this.addNewItem.bind(this);
@ -91,16 +92,18 @@ class AddCoin extends React.Component {
} }
componentWillReceiveProps(props) { componentWillReceiveProps(props) {
if (props && props.display !== this.state.display) { this.existingCoins = props && props.Main ? props.Main.coins : null;
const addCoinProps = props ? props.AddCoin : null;
if (addCoinProps && addCoinProps.display !== this.state.display) {
this.setState(Object.assign({}, this.state, { this.setState(Object.assign({}, this.state, {
display: props.display, display: addCoinProps.display,
modalClassName: props.display ? 'show fade' : 'show fade', modalClassName: addCoinProps.display ? 'show fade' : 'show fade',
})); }));
setTimeout(() => { setTimeout(() => {
this.setState(Object.assign({}, this.state, { this.setState(Object.assign({}, this.state, {
display: props.display, display: addCoinProps.display,
modalClassName: props.display ? 'show in' : 'hide', modalClassName: addCoinProps.display ? 'show in' : 'hide',
})); }));
}, 100); }, 100);
} }
@ -172,8 +175,14 @@ class AddCoin extends React.Component {
} }
activateCoin() { activateCoin() {
const coin = this.state.coins[0].selectedCoin.split('|')[0];
if (this.isCoinAlreadyAdded(coin)) {
this.dismiss();
return;
}
Store.dispatch(addCoin( Store.dispatch(addCoin(
this.state.coins[0].selectedCoin.split('|')[0], coin,
this.state.coins[0].mode, this.state.coins[0].mode,
this.state.coins[0].syncOnly this.state.coins[0].syncOnly
)); ));
@ -211,21 +220,27 @@ class AddCoin extends React.Component {
} }
activateAllCoins() { activateAllCoins() {
Store.dispatch(addCoin( const coin = this.state.coins[0].selectedCoin.split('|')[0];
this.state.coins[0].selectedCoin.split('|')[0], if (!this.isCoinAlreadyAdded(coin)) {
this.state.coins[0].mode, Store.dispatch(addCoin(
this.state.coins[0].syncOnly coin,
)); this.state.coins[0].mode,
this.state.coins[0].syncOnly
));
}
for (let i = 1; i < this.state.coins.length; i++) { for (let i = 1; i < this.state.coins.length; i++) {
const _item = this.state.coins[i]; const _item = this.state.coins[i];
const itemCoin = _item.selectedCoin.split('|')[0];
setTimeout(() => { setTimeout(() => {
Store.dispatch(addCoin( if (!this.isCoinAlreadyAdded(itemCoin)) {
_item.selectedCoin.split('|')[0], Store.dispatch(addCoin(
_item.mode, itemCoin,
_item.syncOnly _item.mode,
)); _item.syncOnly
));
}
if (i === this.state.coins.length - 1) { if (i === this.state.coins.length - 1) {
let _coins = []; let _coins = [];
@ -261,6 +276,20 @@ class AddCoin extends React.Component {
AddCoinRender.call(this) AddCoinRender.call(this)
); );
} }
isCoinAlreadyAdded(coin) {
const modes = ['basilisk', 'full', 'native'];
for (let mode of modes) {
if (this.existingCoins[mode].indexOf(coin) !== -1) {
const message = `${coin} ${translate('ADD_COIN.ALREADY_ADDED')} ${translate('ADD_COIN.IN')} ${mode} ${translate('ADD_COIN.MODE')}`;
Store.dispatch(triggerToaster(message, translate('ADD_COIN.COIN_ALREADY_ADDED'), 'error'));
return true;
}
}
return false;
}
} }
export default AddCoin; export default AddCoin;

2
react/src/components/main/walletMain.js

@ -12,7 +12,7 @@ class WalletMain extends React.Component {
<div className="full-height"> <div className="full-height">
<SyncOnly {...this.props} /> <SyncOnly {...this.props} />
<Dashboard {...this.props} /> <Dashboard {...this.props} />
<AddCoin {...this.props.AddCoin} /> <AddCoin {...this.props} />
<Login {...this.props} /> <Login {...this.props} />
<Toaster {...this.props.toaster} /> <Toaster {...this.props.toaster} />
<Notifications {...this.props} /> <Notifications {...this.props} />

10
react/src/components/toaster/toaster-item.js

@ -13,10 +13,12 @@ class ToasterItem extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
message: null, display: props.display,
type: null, message: props.message,
title: null, type: props._type,
autoClose: true title: props.title,
autoClose: props.autoClose,
toastId: props.toastId
}; };
this.dismissToast = this.dismissToast.bind(this); this.dismissToast = this.dismissToast.bind(this);

6
react/src/translate/en.js

@ -221,7 +221,11 @@ export const _lang = {
'SAVE_SELECTION': 'Save Selection', 'SAVE_SELECTION': 'Save Selection',
'LOAD_SELECTION': 'Load Selection', 'LOAD_SELECTION': 'Load Selection',
'ACTIVATE_ALL': 'Activate all', 'ACTIVATE_ALL': 'Activate all',
'ADD_ANOTHER_COIN': 'Add another coin' 'ADD_ANOTHER_COIN': 'Add another coin',
'ALREADY_ADDED': 'is already added',
'COIN_ALREADY_ADDED': 'Coin already added',
'IN': 'in',
'MODE': 'mode'
}, },
'JUMBLR': { 'JUMBLR': {
'NOTICE': 'EXPERIMENTAL TEST VERSION ONLY', 'NOTICE': 'EXPERIMENTAL TEST VERSION ONLY',

Loading…
Cancel
Save