1
0
mirror of https://github.com/oceanprotocol/react.git synced 2025-02-01 20:39:28 +01:00

use dtSymbol

This commit is contained in:
alexcos20 2020-10-16 04:08:06 -07:00
parent 40929faedf
commit efdfdb8687

View File

@ -49,33 +49,32 @@ function usePricing(): UsePricing {
const [pricingStep, setPricingStep] = useState<number | undefined>() const [pricingStep, setPricingStep] = useState<number | undefined>()
const [pricingStepText, setPricingStepText] = useState<string | undefined>() const [pricingStepText, setPricingStepText] = useState<string | undefined>()
const [pricingError, setPricingError] = useState<string | undefined>() const [pricingError, setPricingError] = useState<string | undefined>()
const [dtSymbol, setDtSymbol] = useState<string>()
function setStepBuyDT(index?: number, datatokenName?: string) { function setStepBuyDT(index?: number) {
setPricingStep(index) setPricingStep(index)
let message let message
if (index) { if (index) {
if (datatokenName) if (dtSymbol) message = buyDTFeedback[index].replace(/DT/g, dtSymbol)
message = buyDTFeedback[index].replace(/DT/g, datatokenName)
else message = buyDTFeedback[index] else message = buyDTFeedback[index]
setPricingStepText(message) setPricingStepText(message)
} }
} }
function setStepSellDT(index?: number, datatokenName?: string) { function setStepSellDT(index?: number) {
setPricingStep(index) setPricingStep(index)
let message let message
if (index) { if (index) {
if (datatokenName) if (dtSymbol) message = sellDTFeedback[index].replace(/DT/g, dtSymbol)
message = sellDTFeedback[index].replace(/DT/g, datatokenName)
else message = sellDTFeedback[index] else message = sellDTFeedback[index]
setPricingStepText(message) setPricingStepText(message)
} }
} }
function setStepCreatePricing(index?: number, datatokenName?: string) { function setStepCreatePricing(index?: number) {
setPricingStep(index) setPricingStep(index)
let message let message
if (index) { if (index) {
if (datatokenName) if (dtSymbol)
message = createPricingFeedback[index].replace(/DT/g, datatokenName) message = createPricingFeedback[index].replace(/DT/g, dtSymbol)
else message = createPricingFeedback[index] else message = createPricingFeedback[index]
setPricingStepText(message) setPricingStepText(message)
} }
@ -91,8 +90,8 @@ function usePricing(): UsePricing {
try { try {
setPricingIsLoading(true) setPricingIsLoading(true)
setPricingError(undefined) setPricingError(undefined)
const datatokenName = await ocean.datatokens.getName(dataTokenAddress) setDtSymbol(await ocean.datatokens.getSymbol(dataTokenAddress))
setStepCreatePricing(0, datatokenName) setStepCreatePricing(0)
switch (priceOptions.type) { switch (priceOptions.type) {
case 'dynamic': { case 'dynamic': {
setStepCreatePricing(2) setStepCreatePricing(2)
@ -146,7 +145,7 @@ function usePricing(): UsePricing {
if (!ocean || !account || !accountId) return null if (!ocean || !account || !accountId) return null
try { try {
const datatokenName = await ocean.datatokens.getName(dataTokenAddress) setDtSymbol(await ocean.datatokens.getSymbol(dataTokenAddress))
setPricingIsLoading(true) setPricingIsLoading(true)
setPricingError(undefined) setPricingError(undefined)
setStepBuyDT(0) setStepBuyDT(0)
@ -155,7 +154,7 @@ function usePricing(): UsePricing {
case 'pool': { case 'pool': {
const price = new Decimal(bestPrice.value).times(1.05).toString() const price = new Decimal(bestPrice.value).times(1.05).toString()
const maxPrice = new Decimal(bestPrice.value).times(2).toString() const maxPrice = new Decimal(bestPrice.value).times(2).toString()
setStepBuyDT(1, datatokenName) setStepBuyDT(1)
Logger.log( Logger.log(
'Buying token from pool', 'Buying token from pool',
bestPrice, bestPrice,
@ -189,7 +188,7 @@ function usePricing(): UsePricing {
bestPrice.value.toString(), bestPrice.value.toString(),
account.getId() account.getId()
) )
setStepBuyDT(1, datatokenName) setStepBuyDT(1)
const exchange = await ocean.fixedRateExchange.buyDT( const exchange = await ocean.fixedRateExchange.buyDT(
bestPrice.address, bestPrice.address,
String(dtAmount), String(dtAmount),
@ -221,14 +220,14 @@ function usePricing(): UsePricing {
return null return null
} }
try { try {
const datatokenName = await ocean.datatokens.getName(dataTokenAddress) setDtSymbol(await ocean.datatokens.getSymbol(dataTokenAddress))
setPricingIsLoading(true) setPricingIsLoading(true)
setPricingError(undefined) setPricingError(undefined)
setStepSellDT(0, datatokenName) setStepSellDT(0)
const pool = await getFirstPool(ocean, dataTokenAddress) const pool = await getFirstPool(ocean, dataTokenAddress)
if (!pool || pool.price === 0) return null if (!pool || pool.price === 0) return null
const price = new Decimal(pool.price).times(0.95).toString() const price = new Decimal(pool.price).times(0.95).toString()
setStepSellDT(1, datatokenName) setStepSellDT(1)
Logger.log('Selling token to pool', pool, account.getId(), price) Logger.log('Selling token to pool', pool, account.getId(), price)
const sellResponse = await ocean.pool.sellDT( const sellResponse = await ocean.pool.sellDT(
account.getId(), account.getId(),