Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handleSendTransaction = async (transport, data, changeIndex, changeKeyIndex, resolve, reject) => {
const arr = [];
if (changeIndex > -1) {
// With change output
arr.push(hathorLib.transaction.intToBytes(1, 1));
// Change index of array
arr.push(hathorLib.transaction.intToBytes(changeIndex, 1));
// Change key index of the address
arr.push(hathorLib.transaction.intToBytes(changeKeyIndex, 4));
} else {
arr.push(hathorLib.transaction.intToBytes(0, 1));
}
const initialData = Buffer.concat(arr);
const initialSize = initialData.length;
const dataBytes = hathorLib.transaction.dataToSign(data);
const totalPieces = Math.ceil((initialSize + dataBytes.length) / 256);
const dataToSend = Buffer.concat([initialData, dataBytes]);
let i = 0;
send = () => {
$('#pinModal').modal('toggle');
const isValid = this.validateData();
if (!isValid) return;
let data = this.getData();
if (!data) return;
data.tokens = hathorLib.tokens.filterTokens(this.state.txTokens, hathorLib.constants.HATHOR_TOKEN_CONFIG).map((token) => token.uid);
this.setState({ errorMessage: '', loading: true });
try {
const promise = hathorLib.transaction.sendTransaction(data, this.state.pin);
promise.then(() => {
// Must update the shared address, in case we have used one for the change
wallet.updateSharedAddress();
this.props.history.push('/wallet/');
}, (message) => {
this.setState({ errorMessage: message, loading: false });
});
} catch(e) {
if (e instanceof hathorLib.errors.AddressError || e instanceof hathorLib.errors.OutputValueError) {
this.setState({ errorMessage: e.message, loading: false });
} else {
// Unhandled error
throw e;
}
}
}
handleGetSignatures = async (transport, data, keys, resolve, reject) => {
const values = []
try {
for (const input of data.inputs) {
const index = keys[input.address].index;
const indexBytes = hathorLib.transaction.intToBytes(index, 4);
const value = await this.sendRequest(transport, this.commands.SEND_TX, 1, 0, indexBytes);
values.push(value);
}
resolve(values);
} catch(e) {
reject(e);
} finally {
// After requesting all signatures we send a last command
// to tell ledger it's done, so it can clear all data for this tx
transport.send(0xe0, this.commands.SEND_TX, 2, 0);
}
}