Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// This token is not the one of this screen
if (output.token !== this.props.token.uid) {
continue;
}
// If output was already used, we can't list it here
if (output.spent_by) {
continue;
}
output.tx_id = tx.tx_id;
output.index = index;
if (hathorLib.wallet.isMintOutput(output)) {
mintOutputs.push(output);
} else if (hathorLib.wallet.isMeltOutput(output)) {
meltOutputs.push(output);
} else if (!hathorLib.wallet.isAuthorityOutput(output)) {
walletAmount += output.value;
}
}
}
// Update user balance of this token
const balance = hathorLib.wallet.calculateBalance(
Object.values(this.props.historyTransactions),
this.props.token.uid
);
this.setState({ mintOutputs, meltOutputs, walletAmount, balance: balance.available });
}
// This token is not the one of this screen
if (output.token !== this.props.token.uid) {
continue;
}
// If output was already used, we can't list it here
if (output.spent_by) {
continue;
}
output.tx_id = tx.tx_id;
output.index = index;
if (hathorLib.wallet.isMintOutput(output)) {
mintOutputs.push(output);
} else if (hathorLib.wallet.isMeltOutput(output)) {
meltOutputs.push(output);
} else if (!hathorLib.wallet.isAuthorityOutput(output)) {
walletAmount += output.value;
}
}
}
// Update user balance of this token
const balance = hathorLib.wallet.calculateBalance(
Object.values(this.props.historyTransactions),
this.props.token.uid
);
this.setState({ mintOutputs, meltOutputs, walletAmount, balance: balance.available });
}
createToken = () => {
$('#pinModal').modal('hide');
if (!this.formValid()) {
return;
}
this.setState({ errorMessage: '', loading: true });
// Get the address to send the created tokens
let address = '';
if (this.refs.autoselectAddress.checked) {
address = hathorLib.wallet.getAddressToUse();
} else {
address = this.refs.address.value;
}
const retPromise = hathorLib.tokens.createToken(
address,
this.refs.shortName.value,
this.refs.symbol.value,
wallet.decimalToInteger(this.state.amount),
this.state.pin
);
retPromise.then((token) => {
// Update redux with added token
tokens.saveTokenRedux(token.uid);
// Must update the shared address, in case we have used one for the change
wallet.updateSharedAddress();
import RequestErrorModal from './components/RequestError';
import DashboardTx from './screens/DashboardTx';
import DecodeTx from './screens/DecodeTx';
import PushTx from './screens/PushTx';
import { dataLoaded, isOnlineUpdate } from "./actions/index";
import store from './store/index';
import createRequestInstance from './api/axiosInstance';
import hathorLib from '@hathor/wallet-lib';
import { DEFAULT_SERVER, VERSION } from './constants';
import LocalStorageStore from './storage.js';
hathorLib.network.setNetwork('mainnet');
hathorLib.storage.setStore(new LocalStorageStore());
// set default server to bravo testnet
hathorLib.wallet.setDefaultServer(DEFAULT_SERVER);
const mapDispatchToProps = dispatch => {
return {
dataLoaded: (data) => dispatch(dataLoaded(data)),
isOnlineUpdate: (data) => dispatch(isOnlineUpdate(data)),
};
};
const mapStateToProps = (state) => {
return {
isVersionAllowed: state.isVersionAllowed,
loadingAddresses: state.loadingAddresses,
};
};
class Root extends React.Component {
generateNewAddress = (e) => {
e.preventDefault();
// We check if the next address was already generated, otherwise we generate, in case we can do it
if (hathorLib.wallet.hasNewAddress()) {
wallet.getNextAddress();
} else {
if (hathorLib.wallet.canGenerateNewAddress()) {
wallet.generateNewAddress();
} else {
this.refs.alertError.show(3000);
}
}
}
const returnStartedRoute = (Component, props, rest) => {
// On Windows the pathname that is being pushed into history has a prefix of '/C:'
// So everytime I use 'push' it works, because I set the pathname
// However when I use history.goBack, it gets the pathname from the history stack
// So it does not find the path because of the prefix
// Besides that, when electron loads initially it needs to load index.html from the filesystem
// So the first load from electron get from '/C:/' in windows. That's why we need the second 'if'
const pathname = rest.location.pathname;
if (pathname.length > 3 && pathname.slice(0,4).toLowerCase() === '/c:/') {
if (pathname.length > 11 && pathname.slice(-11).toLowerCase() !== '/index.html') {
return ;
}
}
if (hathorLib.wallet.started()) {
if (hathorLib.wallet.loaded()) {
if (hathorLib.wallet.isLocked()) {
return ;
} else if (rest.loaded) {
return returnLoadedWalletComponent(Component, props, rest);
} else {
return ;
}
} else {
if (rest.loaded) {
return ;
} else {
return ;
}
}
} else {
const returnLoadedWalletComponent = (Component, props, rest) => {
// For server screen we don't need to check version
const isServerScreen = props.match.path === '/server';
const reduxState = store.getState();
// Check version
if (reduxState.isVersionAllowed === undefined && !isServerScreen) {
const promise = version.checkApiVersion();
promise.then(() => {
wallet.localStorageToRedux();
});
return ;
} else if (reduxState.isVersionAllowed === false && !isServerScreen) {
return ;
} else {
// If was closed and is loaded we need to redirect to locked screen
if (hathorLib.wallet.wasClosed()) {
return ;
} else {
if (reduxState.loadingAddresses && !isServerScreen) {
// If wallet is still loading addresses we redirect to the loading screen
return ;
} else {
return returnDefaultComponent(Component, props);
}
}
}
}
handleInitialData = (data) => {
const noInputs = this.noInputs.current.checked;
const result = hathorLib.wallet.prepareSendTokensData(data, this.state.selected, noInputs, this.props.historyTransactions, this.state.selectedTokens);
if (result.success === false) {
this.props.updateState({ errorMessage: result.message, loading: false });
return null;
}
return result.data;
}
const mapStateToProps = (state) => {
const balance = hathorLib.wallet.calculateBalance(
Object.values(state.historyTransactions),
hathorLib.constants.HATHOR_TOKEN_CONFIG.uid
);
return {
htrBalance: balance.available,
historyTransactions: state.historyTransactions,
};
};
handlePassword = (e) => {
e.preventDefault();
if (this.refs.formPassword.checkValidity() === false) {
this.setState({ passwordFormValidated: true });
} else {
this.setState({ passwordFormValidated: false });
const password = this.refs.password.value;
if (hathorLib.wallet.isPasswordCorrect(password)) {
const words = hathorLib.wallet.getWalletWords(password);
this.props.updateWords(words);
this.setState({ passwordSuccess: true, errorMessage: '' });
} else {
this.setState({errorMessage: 'Invalid password'})
}
}
}