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,
modalClassName: 'hide',
};
this.existingCoins = null;
this.activateCoin = this.activateCoin.bind(this);
this.dismiss = this.dismiss.bind(this);
this.addNewItem = this.addNewItem.bind(this);
@ -91,16 +92,18 @@ class AddCoin extends React.Component {
}
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, {
display: props.display,
modalClassName: props.display ? 'show fade' : 'show fade',
display: addCoinProps.display,
modalClassName: addCoinProps.display ? 'show fade' : 'show fade',
}));
setTimeout(() => {
this.setState(Object.assign({}, this.state, {
display: props.display,
modalClassName: props.display ? 'show in' : 'hide',
display: addCoinProps.display,
modalClassName: addCoinProps.display ? 'show in' : 'hide',
}));
}, 100);
}
@ -172,8 +175,14 @@ class AddCoin extends React.Component {
}
activateCoin() {
const coin = this.state.coins[0].selectedCoin.split('|')[0];
if (this.isCoinAlreadyAdded(coin)) {
this.dismiss();
return;
}
Store.dispatch(addCoin(
this.state.coins[0].selectedCoin.split('|')[0],
coin,
this.state.coins[0].mode,
this.state.coins[0].syncOnly
));
@ -211,21 +220,27 @@ class AddCoin extends React.Component {
}
activateAllCoins() {
Store.dispatch(addCoin(
this.state.coins[0].selectedCoin.split('|')[0],
this.state.coins[0].mode,
this.state.coins[0].syncOnly
));
const coin = this.state.coins[0].selectedCoin.split('|')[0];
if (!this.isCoinAlreadyAdded(coin)) {
Store.dispatch(addCoin(
coin,
this.state.coins[0].mode,
this.state.coins[0].syncOnly
));
}
for (let i = 1; i < this.state.coins.length; i++) {
const _item = this.state.coins[i];
const itemCoin = _item.selectedCoin.split('|')[0];
setTimeout(() => {
Store.dispatch(addCoin(
_item.selectedCoin.split('|')[0],
_item.mode,
_item.syncOnly
));
if (!this.isCoinAlreadyAdded(itemCoin)) {
Store.dispatch(addCoin(
itemCoin,
_item.mode,
_item.syncOnly
));
}
if (i === this.state.coins.length - 1) {
let _coins = [];
@ -261,6 +276,20 @@ class AddCoin extends React.Component {
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;

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

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

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

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

6
react/src/translate/en.js

@ -221,7 +221,11 @@ export const _lang = {
'SAVE_SELECTION': 'Save Selection',
'LOAD_SELECTION': 'Load Selection',
'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': {
'NOTICE': 'EXPERIMENTAL TEST VERSION ONLY',

Loading…
Cancel
Save