2018-10-05 12:34:31 +02:00
|
|
|
import BigNumber from "bignumber.js"
|
|
|
|
import {Receipt} from "web3-utils"
|
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
|
|
|
}
|
|
|
|
|
2018-10-05 12:34:31 +02:00
|
|
|
public async approve(marketAddress: string, price: number, buyerAddress: string): Promise<Receipt> {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-10-05 12:34:31 +02:00
|
|
|
public async balanceOf(address: string): Promise<number> {
|
|
|
|
return this.contract.methods.balanceOf(address)
|
|
|
|
.call()
|
|
|
|
.then((balance: string) => new BigNumber(balance).toNumber())
|
2018-10-01 18:10:26 +02:00
|
|
|
}
|
|
|
|
}
|