Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const send = async ({ net, asset, amount, receiver, address, wif }) => {
if (![GAS, NEO].includes(asset)) {
throw new Error(`Invalid asset: ${asset}`);
}
// TODO check if user has enough balance
if (!wallet.isAddress(receiver)) {
throw new Error(`Invalid script hash: "${receiver}"`);
}
if (amount <= 0) {
throw new Error(`Invalid amount: "${amount}"`);
}
const selectedAsset = asset === NEO ? 'NEO' : 'GAS';
const intents = await api.makeIntent({ [selectedAsset]: amount }, receiver);
const config = {
net,
address,
privateKey: new wallet.Account(wif).privateKey,
intents
};
export default async function getBalances({ net, address, tokens }) {
const endpoint = await api.loadBalance(api.getRPCEndpointFrom, { net });
if (!wallet.isAddress(address)) {
throw new Error(`Invalid script hash: "${address}"`);
}
// token balances
const promises = tokens.map(async (token) => {
const { scriptHash } = token;
try {
const response = await api.nep5.getToken(endpoint, scriptHash, address);
const balance = (response.balance || 0).toString();
return {
[scriptHash]: { ...response, scriptHash, balance }
};
} catch (err) {
// invalid scriptHash
export default async function sendAsset({ net, asset, amount, receiver, address, wif }) {
if (!keys(ASSETS).includes(asset)) {
throw new Error(`Invalid asset: ${asset}`);
}
if (!wallet.isAddress(receiver)) {
throw new Error(`Invalid script hash: "${receiver}"`);
}
if (amount <= 0) {
throw new Error(`Invalid amount: "${amount}"`);
}
const selectedAsset = ASSETS[asset];
const intents = await api.makeIntent({ [selectedAsset]: amount }, receiver);
const config = {
net,
address,
privateKey: new wallet.Account(wif).privateKey,
intents
};
export default function didLogin(oldAddress: ?string, newAddress: ?string) {
return !oldAddress && wallet.isAddress(newAddress)
}
export default function didLogout(oldAddress: ?string, newAddress: ?string) {
return wallet.isAddress(oldAddress) && !newAddress
}
export default async function sendAsset(
{ net, asset, amount, receiver, address, wif, publicKey, signingFunction, remark, fee = 0 },
getBalance = api.neoscan.getBalance,
doSendAsset = api.sendAsset,
doInvoke = api.doInvoke,
doGetRPCEndpoint = getRPCEndpoint
) {
if (!wallet.isAddress(receiver)) {
throw new Error(`Invalid script hash: "${receiver}"`);
}
if (amount <= 0) {
throw new Error(`Invalid amount: "${amount}"`);
}
if (remark !== undefined) {
validateRemark(remark);
}
const send = async () => {
const url = await doGetRPCEndpoint(net);
const config = {
net,
url,
({ address }: WatchOnlyLoginProps) => async (): Promise => {
if (!wallet.isAddress(address)) {
throw new Error('Invalid public key entered')
}
const hasInternetConnectivity = await checkForInternetConnectivity()
return {
address,
isHardwareLogin: false,
isWatchOnly: true,
hasInternetConnectivity,
}
},
)
disableButton = (name: string, address: string) => {
if (name.length === 0) {
return true
}
if (name.length > 100) {
return true
}
if (!wallet.isAddress(address)) {
return true
}
return false
}
export default async function getBalances({ net, address }) {
const endpoint = await getRPCEndpoint(net);
if (!wallet.isAddress(address)) {
throw new Error(`Invalid address: "${address}"`);
}
const assets = await getAssetBalances(endpoint, address);
const tokens = await getTokenBalances(endpoint, address);
return { ...assets, ...tokens };
}
isValid = () => {
const { amount, receiver, asset, balances } = this.props;
const bigNumAmount = this.getAmount(amount);
const bigNumBalance = this.getAmount(balances[asset].balance);
return (
bigNumBalance >= bigNumAmount &&
bigNumAmount > 0 &&
isNumeric(amount) &&
wallet.isAddress(receiver)
);
};
}