Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
indexes.forEach((index: number) => {
const derivationPath = DerivationPath.buildString(
DerivationPath.increment(components, index)
);
paths.push(derivationPath);
});
});
const addresses: Array = [];
const bundle = paths.map((path: string) => ({
path,
showOnTrezor: false,
}));
const response = await TrezorConnect.ethereumGetAddress({
bundle,
}).catch((err: any) => {
console.log("Error:", err);
return { success: false };
});
if (response.success) {
// parse up the bundle results
response.payload.every((item: { address: string, path: Array, serializedPath: string }) => {
return addresses.push({
address: item.address,
derivationPath: item.path,
serializedPath: item.serializedPath,
});
});
indexes.forEach(index => {
const derivationPath = DerivationPath.buildString(
DerivationPath.increment(components, index)
);
paths.push(derivationPath);
});
});
const addresses = [];
const bundle = paths.map(path => ({
path,
showOnTrezor: false
}));
const response = await TrezorConnect.ethereumGetAddress({
bundle
}).catch(err => {
console.log("Error:", err);
return { success: false };
});
if (response.success) {
// parse up the bundle results
response.payload.every(item =>
addresses.push({
address: item.address,
derivationPath: item.path,
serializedPath: item.serializedPath
})
);
if (addresses && addresses.length > 0) {
pageSize = pageSize || 5;
const toAddressIndex = fromAddressIndex + pageSize;
if (this.addressLoaderBusy)
return this.cachedAddresses.slice(fromAddressIndex, toAddressIndex);
this.addressLoaderBusy = true;
if (this.cachedAddresses.length >= toAddressIndex) {
return this.cachedAddresses.slice(fromAddressIndex, toAddressIndex);
}
const bundle = [];
for (let i = 0; i < pageSize; i++) {
bundle.push({
path: this.derivationPath + (fromAddressIndex + i),
showOnTrezor: false,
});
}
const result = await TrezorConnect.ethereumGetAddress({
bundle,
});
this.cachedAddresses.push(...result.payload.map(item => item.address));
return this.cachedAddresses.slice(fromAddressIndex, toAddressIndex);
} catch (e) {
console.log(e);
} finally {
this.addressLoaderBusy = false;
}
}
async connectWallet(derivationPath) {
const { loginWithTrezor, logout } = this.props;
const result = await TrezorConnect.ethereumGetAddress({
path: derivationPath
});
TrezorConnect.on(DEVICE_EVENT, event => {
switch (event.type) {
case DEVICE.DISCONNECT: {
logout();
break;
}
default:
break;
}
});
if (result.success) {
const { address } = result.payload;
const displayAddress = async () => {
await Trezor.ethereumGetAddress({
path: this.basePath + '/' + idx,
showOnTrezor: true
});
};
return new HDWalletInterface(
async getAddress() {
if (this.cachedAddresses && this.addressIndex <= this.cachedAddresses.length) {
return this.cachedAddresses[this.addressIndex];
}
this.cachedAddresses[this.addressIndex] = (await TrezorConnect.ethereumGetAddress({
path: this.derivationPath + this.addressIndex,
showOnTrezor: false,
})).payload.address;
return this.cachedAddresses[this.addressIndex];
}
getAccounts(cb: (err: any, res?: any) => any): void {
TrezorConnect.ethereumGetAddress(path, (response: any) => {
if (response.success) {
cb(null, ["0x" + response.address]);
} else {
cb(response.error);
}
});
},
approveTransaction(_: any, cb: (err: any, res?: any) => any): void {
const displayAddress = async () => {
await Trezor.ethereumGetAddress({
path: this.basePath + '/' + idx,
showOnTrezor: true
});
};
return new HDWalletInterface(
getAddresses = async ({ from = 0, to = 9 } = {}) => {
const { success, payload } = await TrezorConnect.ethereumGetAddress(
this.getAddsParams({ from, to })
)
return { success, payload }
}
async connectWallet(derivationPath: string) {
const { loginWithTrezor, logout } = this.props;
const result = await TrezorConnect.ethereumGetAddress({
path: derivationPath,
});
TrezorConnect.on(DEVICE_EVENT, (event: any) => {
switch (event.type) {
case DEVICE.DISCONNECT: {
logout();
break;
}
default:
break;
}
});
if (result.success) {
const { address } = result.payload;