2018-10-02 10:06:26 +02:00
|
|
|
import Config from "../models/Config"
|
|
|
|
import ContractBaseWrapper from "./ContractWrapperBase"
|
|
|
|
import Web3Helper from "./Web3Helper"
|
2018-10-01 18:10:26 +02:00
|
|
|
|
|
|
|
export default class OceanToken extends ContractBaseWrapper {
|
|
|
|
|
|
|
|
public static async getInstance(config: Config, web3Helper: Web3Helper) {
|
2018-10-02 10:06:26 +02:00
|
|
|
const token = new OceanToken(config, "OceanToken", web3Helper)
|
|
|
|
await token.init()
|
|
|
|
return token
|
2018-10-01 18:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public async getTokenBalance(accountAddress: string) {
|
2018-10-02 10:06:26 +02:00
|
|
|
return this.contract.methods.balanceOf(accountAddress).call()
|
2018-10-01 18:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public async getEthBalance(account: string): Promise<number> {
|
|
|
|
return new Promise<number>((resolve, reject) => {
|
|
|
|
// Logger.log("getting balance for", account);
|
|
|
|
this.web3Helper.getWeb3().eth.getBalance(account, "latest", (err: any, balance: number) => {
|
|
|
|
if (err) {
|
2018-10-02 10:06:26 +02:00
|
|
|
return reject(err)
|
2018-10-01 18:10:26 +02:00
|
|
|
}
|
|
|
|
// Logger.log("balance", balance);
|
2018-10-02 10:06:26 +02:00
|
|
|
resolve(balance)
|
|
|
|
})
|
|
|
|
})
|
2018-10-01 18:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public async approve(marketAddress: string, price: number, buyerAddress: string) {
|
|
|
|
return this.contract.methods.approve(marketAddress, price).send({
|
|
|
|
from: buyerAddress,
|
|
|
|
gas: this.config.defaultGas,
|
2018-10-02 10:06:26 +02:00
|
|
|
})
|
2018-10-01 18:10:26 +02:00
|
|
|
}
|
|
|
|
}
|