Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async loadMore() {
const transport = await this.transport()
const getTransport = () => transport
const path = this.selectedPath
const networkId = Number(this.state.ethereum.networkId)
const accountsLength = 4
const offset = this.accounts.length
// stop the loop when selectedPath has chaned or max accounts reached
if (offset + accountsLength >= 100) {
return
}
// console.log("loading,", path, offset, networkId, accountsLength)
this.loadingAccounts = true
const ledger = createLedgerSubprovider(
getTransport
, {
networkId,
accountsLength,
path: this.calculatePath(path, offset),
})
const t = Date.now()
// console.log("getAccounts")
ledger.getAccounts((error, accounts: string[]) => {
console.log("getAccounts", (Date.now() - t) / 1000)
if (error) {
// show error "please unlock your ledger wallet and go to the etherum app"
console.log(error)
} else {
from(accounts)
return new Promise(async (resolve, reject) => {
const engine = new ProviderEngine()
const getTransport = () => TransportU2F.create()
const ledger = createLedgerSubprovider(getTransport, {
networkId: 1,
// maybe we only need 1 now that we solved this
accountsLength: 5,
path,
})
ledger.signMessage = ledger.signPersonalMessage
engine.addProvider(ledger)
engine.addProvider(
new FetchSubprovider({
rpcUrl: "https://mainnet.infura.io/5Ic91y0T9nLh6qUg33K0",
}),
)
engine.start()
resolve(new Web3(engine))
})
async connect(account: LedgerAccount) {
const selectedAddress = account.address
const path = this.calculatePath(this.selectedPath, this.accounts.indexOf(account))
const networkId = Number(this.state.ethereum.networkId)
const rpcUrl = this.state.ethereum.endpoint
const engine = new ProviderEngine()
const transport = await this.transport()
const ledger = createLedgerSubprovider(
() => transport, {
networkId,
accountsLength: 1,
path,
})
ledger.signMessage = ledger.signPersonalMessage
engine.addProvider(ledger)
engine.addProvider(
// new RpcSubprovider({ rpcUrl }),
new FetchSubprovider({
rpcUrl,
}),
)
engine.start()
// @ts-ignore
constructor(opts?: SubproviderOptions,
providerUrl?: string) {
opts = Object.assign({
accountsLength: 5
}, opts);
const getTransport = () => TransportU2F.create();
const ledger = createLedgerSubprovider(getTransport, opts);
const rpcProvider = new RpcSubprovider({
rpcUrl: providerUrl || DEFAULT_RPC_URL
});
this.engine = new ProviderEngine({pollingInterval: 10000});
this.engine.addProvider(ledger);
this.engine.addProvider(rpcProvider);
this.engine.start(); // Required by the provider engine.
}
export async function getLedgerWeb3() {
if (!_ledgerWeb3Instance) {
const engine = new ProviderEngine();
const getTransport = () => TransportU2F.create();
const ledger = createLedgerSubprovider(getTransport, {
networkId,
accountsLength: 5,
});
engine.addProvider(ledger);
engine.addProvider(new FetchSubprovider({ rpcUrl }));
engine.start();
_ledgerWeb3Instance = new Web3(engine);
}
return _ledgerWeb3Instance;
}
createWeb3(accountsOffset, accountsQuantity) {
accountsOffset = accountsOffset || 0;
accountsQuantity = accountsQuantity || 6;
const engine = new ProviderEngine();
const getTransport = () => HWTransportNodeHid.create();
const ledger = Web3SubProvider(getTransport, {
networkId: chainId,
accountsLength: accountsQuantity,
accountsOffset
});
engine.addProvider(ledger);
engine.addProvider(new FetchSubprovider({ rpcUrl: SELECTED_SERVER_URL }));
engine.start();
return new Web3(engine);
}
signTransaction(args) {
export function getProvider() {
const ethNet = appConfig().network;
const networkId = appConfig().networkId;
const rpcUrl = getNodeUrl(ethNet);
const engine = new ProviderEngine();
const getTransport = async () => TransportU2F.create();
const ledger = createLedgerSubprovider(getTransport, {
networkId,
accountsLength: 5,
});
engine.addProvider(ledger);
engine.addProvider(new FetchSubprovider({ rpcUrl }));
engine.start();
return engine;
}
return new Promise(async (resolve, reject) => {
const engine = new ProviderEngine()
const getTransport = () => TransportU2F.create()
const ledger = createLedgerSubprovider(getTransport, {
networkId: 1,
accountsLength: 10,
path,
})
const accounts = ledger.getAccounts((err, val) => {
if (err) reject(err)
resolve(val)
})
})
}
return new Promise(async (resolve, reject) => {
const engine = new ProviderEngine()
const getTransport = () => TransportU2F.create()
const ledger = createLedgerSubprovider(getTransport, {
networkId: 1,
accountsLength: 5,
})
ledger.getAccounts = () => ["123"]
ledger.signMessage = ledger.signPersonalMessage
engine.addProvider(ledger)
engine.addProvider(
new FetchSubprovider({
rpcUrl: "https://mainnet.infura.io/5Ic91y0T9nLh6qUg33K0",
}),
)
engine.start()
resolve(new Web3(engine))
})
window.provider = (config) => {
const basicProvider = new ethers.providers.InfuraProvider(config.provider.network);
const engine = new ProviderEngine();
const getTransport = () => TransportU2F.create();
const ledger = createLedgerSubprovider(getTransport, { accountsLength: 1 });
engine.addProvider(ledger);
engine.addProvider(new RpcSubprovider({ rpcUrl: '${basicProvider.baseUrl}/api' }));
engine.start();
return engine;
}