Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function requirePayment(toAddress: string, amount: number, currency: string): Promise {
try {
let fromAddress = await getUserAccount()
if (!fromAddress) {
throw new Error(`Not a web3 game session`)
}
let result: Promise
if (currency === 'ETH') {
result = requestManager.eth_sendTransaction({
to: toAddress,
from: fromAddress,
// TODO: fix this in eth-connect
value: toWei(amount as any, 'ether') as any,
data: null as any
})
} else {
const supportedTokens: Record = {} // a TODO: getNetworkConfigurations(network).paymentTokens
if (currency in supportedTokens === false) {
// tslint:disable:no-console
console.warn(`WARNING! Using a non-supported coin. Skipping operation! Please use one of the next coins 'ETH'`)
return false
}
const contractInstance = await getERC20(requestManager, supportedTokens[currency])
// Check this account has enough tokens for the transaction
const balance = await getERC20Balance(fromAddress, contractInstance.address)
if (balance.lt(amount)) {