Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handleWebsocket = (wsData) => {
if (hathorLib.wallet.loaded()) {
// We are still receiving lot of ws messages that are destined to the admin-frontend and not this wallet
// TODO separate those messages
if (wsData.type === 'wallet:address_history') {
// If is a new transaction, we send a notification to the user, in case it's turned on
// We only send the notification if the inputs are not generated from this wallet
if (!hathorLib.wallet.txExists(wsData.history) && !hathorLib.wallet.areInputsMine(wsData.history)) {
let message = '';
if (hathorLib.helpers.isBlock(wsData.history)) {
message = 'You\'ve found a new block! Click to open it.';
} else {
message = 'You\'ve received a new transaction! Click to open it.'
}
const notification = wallet.sendNotification(message);
// Set the notification click, in case we have sent one
if (notification !== undefined) {
notification.onclick = () => {
this.props.history.push(`/transaction/${wsData.history.tx_id}/`);
}
}
}
wallet.newAddressHistory(wsData.history);
} else {
console.log('Websocket message not handled. Type:', wsData.type);
}
getConfirmationData = () => {
hathorLib.txApi.getConfirmationData(this.state.transaction.hash, (data) => {
this.setState({ confirmationData: data });
}, (e) => {
// Error in request
console.log(e);
});
}
buttonClicked = () => {
hathorLib.txApi.decodeTx(this.state.dataToDecode, (data) => {
this.txDecoded(data);
}, (e) => {
// Error in request
console.log(e);
});
}
// 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);
}
}
}
}