1
0
mirror of https://github.com/oceanprotocol/react.git synced 2024-11-22 09:47:06 +01:00

Merge pull request #167 from oceanprotocol/bug/fix_minting

fix mint
This commit is contained in:
mihaisc 2020-10-27 18:31:33 +02:00 committed by GitHub
commit 8903b86e20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,7 +22,7 @@ interface UsePricing {
) => Promise<TransactionReceipt | string | void>
buyDT: (dtAmount: number | string) => Promise<TransactionReceipt | void>
sellDT: (dtAmount: number | string) => Promise<TransactionReceipt | void>
mint: (tokensToMint: string) => Promise<TransactionReceipt>
mint: (tokensToMint: string) => Promise<TransactionReceipt | void>
pricingStep?: number
pricingStepText?: string
pricingError?: string
@ -83,10 +83,23 @@ function usePricing(ddo: DDO): UsePricing {
setPricingStepText(messages[index])
}
async function mint(tokensToMint: string): Promise<TransactionReceipt> {
async function mint(
tokensToMint: string
): Promise<TransactionReceipt | void> {
Logger.log('mint function', dataToken, accountId)
const tx = await ocean.datatokens.mint(dataToken, accountId, tokensToMint)
return tx
const balance = new Decimal(
await ocean.datatokens.balance(dataToken, accountId)
)
const tokens = new Decimal(tokensToMint)
if (tokens.greaterThan(balance)) {
const mintAmount = tokens.minus(balance)
const tx = await ocean.datatokens.mint(
dataToken,
accountId,
mintAmount.toString()
)
return tx
}
}
async function buyDT(