Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getBalance(addr: string): Promise> {
const address = validation.isBech32(addr) ? fromBech32Address(addr) : addr;
return this.provider.send(
RPCMethod.GetBalance,
address.replace('0x', '').toLowerCase(),
);
}
const AccountInfo = ({ address, getBalance }) => {
const bech32Address = toBech32Address(address);
const { data, error, isPending, run } = useAsyncFn({ promiseFn: getBalance });
return (
<div>
<div>
<h5>
<b>{'Account Info'}</b>
</h5>
<div>
<div>
{bech32Address ? (
) : null}
</div>
<div>
<b>{'Address'}</b>
<p>
<a rel="noopener noreferrer" href="{getAddressExplorerURL(bech32Address)}">{`${bech32Address}`}</a>{' '}
<br>
<small>{`(ByStr20: ${address})`}</small>
</p>
<b></b></div></div></div></div>
getSmartContracts(
addr: string,
): Promise, string>> {
const address = validation.isBech32(addr) ? fromBech32Address(addr) : addr;
return this.provider.send(
RPCMethod.GetSmartContracts,
address.replace('0x', '').toLowerCase(),
);
}
async ledgerGetAddress() {
this.spiner();
const hwIndex = this.ladgerIndex;
const hwType = 'ledger';
try {
if (isNaN(hwIndex)) {
throw new Error('index must be number');
}
let { pubAddr, publicKey } = await ledgerControll.getAddresses(
hwIndex
);
pubAddr = fromBech32Address(pubAddr);
await this.importByHw({
pubAddr, hwIndex, hwType, publicKey
});
this.spiner();
this.$router.push({ name: 'Home' });
return null;
} catch(err) {
this.ledgerErr = err.message;
}
this.spiner();
}
}
yield delay(500);
try {
const { payload } = action;
const { toAddress, amount } = payload;
const zilState = yield select(getZilState);
const { zilliqa, provider, privateKey, address, publicKey } = zilState;
const response = yield zilliqa.blockchain.getMinimumGasPrice();
const minGasPriceInQa: string = response.result;
const nonceResponse = yield zilliqa.blockchain.getBalance(address);
const nonceData = nonceResponse.result.nonce || { nonce: 0 };
const nonce: number = nonceData.nonce + 1;
const toAddr = fromBech32Address(toAddress);
const wallet = zilliqa.wallet;
wallet.addByPrivateKey(privateKey);
const tx = new Transaction(
{
version: VERSION,
toAddr,
amount: units.toQa(amount, units.Units.Zil),
gasPrice: new BN(minGasPriceInQa),
gasLimit: Long.fromNumber(1),
pubKey: publicKey,
nonce
},
provider
);
getSmartContractCode(
addr: string,
): Promise> {
const address = validation.isBech32(addr) ? fromBech32Address(addr) : addr;
return this.provider.send(
RPCMethod.GetSmartContractCode,
address.replace('0x', '').toLowerCase(),
);
}
'toAddr'
].forEach(key => {
if (!payload.hasOwnProperty(key)) {
throw new Error(
errorsCode.WrongRequiredparam + key
);
}
});
const storage = new BrowserStorage();
let forConfirm = await storage.get(fields.CONFIRM_TX);
if (validation.isBase58(payload.toAddr)) {
payload.toAddr = decodeBase58(payload.toAddr);
} else if (validation.isBech32(payload.toAddr)) {
payload.toAddr = fromBech32Address(payload.toAddr);
}
payload.toAddr = toChecksumAddress(payload.toAddr);
try {
forConfirm = forConfirm[fields.CONFIRM_TX];
forConfirm.push(payload);
} catch(err) {
forConfirm = [payload];
}
await storage.set(new BuildObject(fields.CONFIRM_TX, forConfirm));
this.notificationsCounter(forConfirm);
}
for (let index = 0; index < neededParams.length; index++) {
const param = neededParams[index]
if (!(param in payload)) {
throw new Error(
errorsCode.WrongRequiredparam + param
)
}
}
const storage = new BrowserStorage()
let forConfirm = await storage.get(FIELDS.CONFIRM_TX)
if (validation.isBech32(payload.toAddr)) {
payload.toAddr = fromBech32Address(payload.toAddr)
}
payload.toAddr = toChecksumAddress(payload.toAddr)
try {
forConfirm.push(payload)
} catch (err) {
forConfirm = [payload]
}
await storage.set(
new BuildObject(FIELDS.CONFIRM_TX, forConfirm)
)
this.notificationsCounter(forConfirm)
}
public faucet = async ({ args, signal }): Promise => {
const { token, toAddress } = args;
const address = fromBech32Address(toAddress);
const body = JSON.stringify({ address, token });
const res = await fetch(`${getHost(window.location.hostname)}/faucet/run`, {
signal,
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body
});
if (!res.ok) throw new Error('Failed to run faucet');
const data = await res.json();
return data ? data.txId : undefined;
};
getSmartContractState(addr: string): Promise> {
const address = validation.isBech32(addr) ? fromBech32Address(addr) : addr;
return this.provider.send(
RPCMethod.GetSmartContractState,
address.replace('0x', '').toLowerCase(),
);
}