mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Remove try...catch from Dispenser
This commit is contained in:
parent
e5cdeee702
commit
bf1eab7df8
@ -17,16 +17,11 @@ export class Dispenser extends SmartContractWithAddress {
|
||||
* @return {Promise<FixedPricedExchange>} Exchange details
|
||||
*/
|
||||
public async status(dtAdress: string): Promise<DispenserToken> {
|
||||
try {
|
||||
const status: DispenserToken = await this.contract.methods.status(dtAdress).call()
|
||||
status.maxTokens = this.web3.utils.fromWei(status.maxTokens)
|
||||
status.maxBalance = this.web3.utils.fromWei(status.maxBalance)
|
||||
status.balance = this.web3.utils.fromWei(status.balance)
|
||||
return status
|
||||
} catch (e) {
|
||||
LoggerInstance.warn(`No dispenser available for datatoken: ${dtAdress}`)
|
||||
}
|
||||
return null
|
||||
const status: DispenserToken = await this.contract.methods.status(dtAdress).call()
|
||||
status.maxTokens = this.web3.utils.fromWei(status.maxTokens)
|
||||
status.maxBalance = this.web3.utils.fromWei(status.maxBalance)
|
||||
status.balance = this.web3.utils.fromWei(status.balance)
|
||||
return status
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,32 +84,27 @@ export class Dispenser extends SmartContractWithAddress {
|
||||
address: string,
|
||||
estimateGas?: G
|
||||
): Promise<G extends false ? TransactionReceipt : number> {
|
||||
try {
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.activate,
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.activate,
|
||||
dtAddress,
|
||||
this.web3.utils.toWei(maxTokens),
|
||||
this.web3.utils.toWei(maxBalance)
|
||||
)
|
||||
if (estimateGas) return estGas
|
||||
|
||||
const trxReceipt = await this.contract.methods
|
||||
.activate(
|
||||
dtAddress,
|
||||
this.web3.utils.toWei(maxTokens),
|
||||
this.web3.utils.toWei(maxBalance)
|
||||
)
|
||||
if (estimateGas) return estGas
|
||||
|
||||
const trxReceipt = await this.contract.methods
|
||||
.activate(
|
||||
dtAddress,
|
||||
this.web3.utils.toWei(maxTokens),
|
||||
this.web3.utils.toWei(maxBalance)
|
||||
)
|
||||
.send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await this.getFairGasPrice()
|
||||
})
|
||||
return trxReceipt
|
||||
} catch (e) {
|
||||
LoggerInstance.error(`ERROR: Failed to activate dispenser: ${e.message}`)
|
||||
}
|
||||
return null
|
||||
.send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await this.getFairGasPrice()
|
||||
})
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
@ -128,24 +118,19 @@ export class Dispenser extends SmartContractWithAddress {
|
||||
address: string,
|
||||
estimateGas?: G
|
||||
): Promise<G extends false ? TransactionReceipt : number> {
|
||||
try {
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.deactivate,
|
||||
dtAddress
|
||||
)
|
||||
if (estimateGas) return estGas
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.deactivate,
|
||||
dtAddress
|
||||
)
|
||||
if (estimateGas) return estGas
|
||||
|
||||
const trxReceipt = await this.contract.methods.deactivate(dtAddress).send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await this.getFairGasPrice()
|
||||
})
|
||||
return trxReceipt
|
||||
} catch (e) {
|
||||
LoggerInstance.error(`ERROR: Failed to activate dispenser: ${e.message}`)
|
||||
}
|
||||
return null
|
||||
const trxReceipt = await this.contract.methods.deactivate(dtAddress).send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await this.getFairGasPrice()
|
||||
})
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
@ -161,27 +146,22 @@ export class Dispenser extends SmartContractWithAddress {
|
||||
newAllowedSwapper: string,
|
||||
estimateGas?: G
|
||||
): Promise<G extends false ? TransactionReceipt : number> {
|
||||
try {
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.setAllowedSwapper,
|
||||
dtAddress,
|
||||
newAllowedSwapper
|
||||
)
|
||||
if (estimateGas) return estGas
|
||||
const estGas = await calculateEstimatedGas(
|
||||
address,
|
||||
this.contract.methods.setAllowedSwapper,
|
||||
dtAddress,
|
||||
newAllowedSwapper
|
||||
)
|
||||
if (estimateGas) return estGas
|
||||
|
||||
const trxReceipt = await this.contract.methods
|
||||
.setAllowedSwapper(dtAddress, newAllowedSwapper)
|
||||
.send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await this.getFairGasPrice()
|
||||
})
|
||||
return trxReceipt
|
||||
} catch (e) {
|
||||
LoggerInstance.error(`ERROR: Failed to activate dispenser: ${e.message}`)
|
||||
}
|
||||
return null
|
||||
const trxReceipt = await this.contract.methods
|
||||
.setAllowedSwapper(dtAddress, newAllowedSwapper)
|
||||
.send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await this.getFairGasPrice()
|
||||
})
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
@ -210,19 +190,14 @@ export class Dispenser extends SmartContractWithAddress {
|
||||
)
|
||||
if (estimateGas) return estGas
|
||||
|
||||
try {
|
||||
const trxReceipt = await this.contract.methods
|
||||
.dispense(dtAddress, this.web3.utils.toWei(amount), destination)
|
||||
.send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await this.getFairGasPrice()
|
||||
})
|
||||
return trxReceipt
|
||||
} catch (e) {
|
||||
LoggerInstance.error(`ERROR: Failed to dispense tokens: ${e.message}`)
|
||||
}
|
||||
return null
|
||||
const trxReceipt = await this.contract.methods
|
||||
.dispense(dtAddress, this.web3.utils.toWei(amount), destination)
|
||||
.send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await this.getFairGasPrice()
|
||||
})
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
@ -243,17 +218,12 @@ export class Dispenser extends SmartContractWithAddress {
|
||||
)
|
||||
if (estimateGas) return estGas
|
||||
|
||||
try {
|
||||
const trxReceipt = await this.contract.methods.ownerWithdraw(dtAddress).send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await this.getFairGasPrice()
|
||||
})
|
||||
return trxReceipt
|
||||
} catch (e) {
|
||||
LoggerInstance.error(`ERROR: Failed to withdraw tokens: ${e.message}`)
|
||||
}
|
||||
return null
|
||||
const trxReceipt = await this.contract.methods.ownerWithdraw(dtAddress).send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: await this.getFairGasPrice()
|
||||
})
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user