mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
update start compute flow messages
This commit is contained in:
parent
4eb41bba2c
commit
62f5803e49
@ -18,9 +18,16 @@ export function getCollectTokensFeedback(
|
|||||||
return `Collecting ${baseTokenBalance} ${baseTokenSymbol} from asset `
|
return `Collecting ${baseTokenBalance} ${baseTokenSymbol} from asset `
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: customize for compute
|
export function getComputeFeedback(
|
||||||
export const computeFeedback: { [key in number]: string } = {
|
baseTokenSymbol?: string,
|
||||||
0: 'Ordering asset...',
|
datatokenSymbol?: string,
|
||||||
1: 'Transfering datatoken.',
|
assetType?: string
|
||||||
2: 'Access granted. Starting job...'
|
): { [key in number]: string } {
|
||||||
|
return {
|
||||||
|
0: `Setting price and fees for ${assetType}`,
|
||||||
|
1: `Approving and buying one ${datatokenSymbol} from pool`,
|
||||||
|
2: `Ordering ${assetType} and transfering datatoken ...`,
|
||||||
|
3: `Approving ${baseTokenSymbol} and ordering ${assetType}`,
|
||||||
|
4: 'Generating signature. Starting compute job ...'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
BIN
src/components/Asset/AssetActions/Compute/.index.tsx.swp
Normal file
BIN
src/components/Asset/AssetActions/Compute/.index.tsx.swp
Normal file
Binary file not shown.
@ -42,6 +42,7 @@ import { OrderPriceAndFees } from 'src/@types/Price'
|
|||||||
import { buyDtFromPool } from '@utils/pool'
|
import { buyDtFromPool } from '@utils/pool'
|
||||||
import { order } from '@utils/order'
|
import { order } from '@utils/order'
|
||||||
import { AssetExtended } from 'src/@types/AssetExtended'
|
import { AssetExtended } from 'src/@types/AssetExtended'
|
||||||
|
import { getComputeFeedback } from '@utils/feedback'
|
||||||
|
|
||||||
export default function Compute({
|
export default function Compute({
|
||||||
asset,
|
asset,
|
||||||
@ -73,18 +74,15 @@ export default function Compute({
|
|||||||
|
|
||||||
const [isOwned, setIsOwned] = useState(false)
|
const [isOwned, setIsOwned] = useState(false)
|
||||||
const [validOrderTx, setValidOrderTx] = useState('')
|
const [validOrderTx, setValidOrderTx] = useState('')
|
||||||
const [orderPriceAndFees, setOrderPriceAndFees] =
|
|
||||||
useState<OrderPriceAndFees>()
|
|
||||||
const [isAlgorithmOwned, setIsAlgorithmOwned] = useState(false)
|
const [isAlgorithmOwned, setIsAlgorithmOwned] = useState(false)
|
||||||
const [validAlgorithmOrderTx, setValidAlgorithmOrderTx] = useState('')
|
const [validAlgorithmOrderTx, setValidAlgorithmOrderTx] = useState('')
|
||||||
const [orderAlgorithmPriceAndFees, setOrderAlgorithmPriceAndFees] =
|
|
||||||
useState<OrderPriceAndFees>()
|
|
||||||
|
|
||||||
const hasDatatoken = Number(dtBalance) >= 1
|
const hasDatatoken = Number(dtBalance) >= 1
|
||||||
const isMounted = useIsMounted()
|
const isMounted = useIsMounted()
|
||||||
const newCancelToken = useCancelToken()
|
const newCancelToken = useCancelToken()
|
||||||
const [isConsumablePrice, setIsConsumablePrice] = useState(true)
|
const [isConsumablePrice, setIsConsumablePrice] = useState(true)
|
||||||
const [isAlgoConsumablePrice, setIsAlgoConsumablePrice] = useState(true)
|
const [isAlgoConsumablePrice, setIsAlgoConsumablePrice] = useState(true)
|
||||||
|
const [computeStatusText, setComputeStatusText] = useState('')
|
||||||
const isComputeButtonDisabled =
|
const isComputeButtonDisabled =
|
||||||
isJobStarting === true ||
|
isJobStarting === true ||
|
||||||
file === null ||
|
file === null ||
|
||||||
@ -108,30 +106,9 @@ export default function Compute({
|
|||||||
setIsConsumablePrice(asset?.accessDetails?.isPurchasable)
|
setIsConsumablePrice(asset?.accessDetails?.isPurchasable)
|
||||||
setIsOwned(asset?.accessDetails?.isOwned)
|
setIsOwned(asset?.accessDetails?.isOwned)
|
||||||
setValidOrderTx(asset?.accessDetails?.validOrderTx)
|
setValidOrderTx(asset?.accessDetails?.validOrderTx)
|
||||||
|
|
||||||
async function init() {
|
|
||||||
if (asset?.accessDetails?.addressOrId === ZERO_ADDRESS) return
|
|
||||||
const computeEnv = await getComputeEnviroment(asset)
|
|
||||||
const validUntil = getValidUntilTime(
|
|
||||||
computeEnv?.maxJobDuration,
|
|
||||||
asset?.services[0]?.timeout
|
|
||||||
)
|
|
||||||
const orderPriceAndFees = await getOrderPriceAndFees(
|
|
||||||
asset,
|
|
||||||
ZERO_ADDRESS,
|
|
||||||
computeEnv?.id,
|
|
||||||
validUntil
|
|
||||||
)
|
|
||||||
setOrderPriceAndFees(orderPriceAndFees)
|
|
||||||
}
|
|
||||||
init()
|
|
||||||
}, [asset?.accessDetails])
|
}, [asset?.accessDetails])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log(
|
|
||||||
'selectedAlgorithmAsset?.accessDetails == ',
|
|
||||||
selectedAlgorithmAsset?.accessDetails
|
|
||||||
)
|
|
||||||
if (!selectedAlgorithmAsset?.accessDetails || !accountId) return
|
if (!selectedAlgorithmAsset?.accessDetails || !accountId) return
|
||||||
|
|
||||||
checkAssetDTBalance(selectedAlgorithmAsset)
|
checkAssetDTBalance(selectedAlgorithmAsset)
|
||||||
@ -140,26 +117,6 @@ export default function Compute({
|
|||||||
setValidAlgorithmOrderTx(
|
setValidAlgorithmOrderTx(
|
||||||
selectedAlgorithmAsset?.accessDetails?.validOrderTx
|
selectedAlgorithmAsset?.accessDetails?.validOrderTx
|
||||||
)
|
)
|
||||||
|
|
||||||
async function init() {
|
|
||||||
if (selectedAlgorithmAsset?.accessDetails?.addressOrId === ZERO_ADDRESS)
|
|
||||||
return
|
|
||||||
const computeEnv = await getComputeEnviroment(selectedAlgorithmAsset)
|
|
||||||
const validUntil = getValidUntilTime(
|
|
||||||
computeEnv?.maxJobDuration,
|
|
||||||
asset?.services[0]?.timeout,
|
|
||||||
selectedAlgorithmAsset?.services[0]?.timeout
|
|
||||||
)
|
|
||||||
const orderPriceAndFees = await getOrderPriceAndFees(
|
|
||||||
selectedAlgorithmAsset,
|
|
||||||
ZERO_ADDRESS,
|
|
||||||
computeEnv?.id,
|
|
||||||
validUntil
|
|
||||||
)
|
|
||||||
setOrderAlgorithmPriceAndFees(orderPriceAndFees)
|
|
||||||
console.log('orderPriceAndFees ', orderPriceAndFees)
|
|
||||||
}
|
|
||||||
init()
|
|
||||||
}, [selectedAlgorithmAsset])
|
}, [selectedAlgorithmAsset])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -215,6 +172,26 @@ export default function Compute({
|
|||||||
asset.services[0].timeout,
|
asset.services[0].timeout,
|
||||||
selectedAlgorithmAsset.services[0].timeout
|
selectedAlgorithmAsset.services[0].timeout
|
||||||
)
|
)
|
||||||
|
|
||||||
|
setComputeStatusText(
|
||||||
|
getComputeFeedback(
|
||||||
|
asset.accessDetails.baseToken?.symbol,
|
||||||
|
asset.accessDetails.datatoken?.symbol,
|
||||||
|
asset.metadata.type
|
||||||
|
)[0]
|
||||||
|
)
|
||||||
|
const datasetPriceAndFees = await getOrderPriceAndFees(
|
||||||
|
asset,
|
||||||
|
ZERO_ADDRESS,
|
||||||
|
computeEnv?.id,
|
||||||
|
validUntil
|
||||||
|
)
|
||||||
|
if (!datasetPriceAndFees) {
|
||||||
|
setError('Error setting dataset price and fees!')
|
||||||
|
toast.error('Error setting dataset price and fees!')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let datasetOrderTx
|
let datasetOrderTx
|
||||||
if (isOwned) {
|
if (isOwned) {
|
||||||
datasetOrderTx = validOrderTx
|
datasetOrderTx = validOrderTx
|
||||||
@ -222,6 +199,13 @@ export default function Compute({
|
|||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
if (!hasDatatoken && asset?.accessDetails.type === 'dynamic') {
|
if (!hasDatatoken && asset?.accessDetails.type === 'dynamic') {
|
||||||
|
setComputeStatusText(
|
||||||
|
getComputeFeedback(
|
||||||
|
asset.accessDetails.baseToken?.symbol,
|
||||||
|
asset.accessDetails.datatoken?.symbol,
|
||||||
|
asset.metadata.type
|
||||||
|
)[1]
|
||||||
|
)
|
||||||
const tx = await buyDtFromPool(
|
const tx = await buyDtFromPool(
|
||||||
asset?.accessDetails,
|
asset?.accessDetails,
|
||||||
accountId,
|
accountId,
|
||||||
@ -233,11 +217,18 @@ export default function Compute({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LoggerInstance.log('dataset orderPriceAndFees: ', orderPriceAndFees)
|
LoggerInstance.log('dataset orderPriceAndFees: ', datasetPriceAndFees)
|
||||||
|
setComputeStatusText(
|
||||||
|
getComputeFeedback(
|
||||||
|
asset.accessDetails.baseToken?.symbol,
|
||||||
|
asset.accessDetails.datatoken?.symbol,
|
||||||
|
asset.metadata.type
|
||||||
|
)[asset.accessDetails?.type === 'fixed' ? 3 : 2]
|
||||||
|
)
|
||||||
const orderTx = await order(
|
const orderTx = await order(
|
||||||
web3,
|
web3,
|
||||||
asset,
|
asset,
|
||||||
orderPriceAndFees,
|
datasetPriceAndFees,
|
||||||
accountId,
|
accountId,
|
||||||
computeEnv?.id,
|
computeEnv?.id,
|
||||||
validUntil,
|
validUntil,
|
||||||
@ -261,6 +252,26 @@ export default function Compute({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setComputeStatusText(
|
||||||
|
getComputeFeedback(
|
||||||
|
selectedAlgorithmAsset.accessDetails.baseToken?.symbol,
|
||||||
|
selectedAlgorithmAsset.accessDetails.datatoken?.symbol,
|
||||||
|
selectedAlgorithmAsset.metadata.type
|
||||||
|
)[0]
|
||||||
|
)
|
||||||
|
const algorithmOrderPriceAndFees = await getOrderPriceAndFees(
|
||||||
|
selectedAlgorithmAsset,
|
||||||
|
ZERO_ADDRESS,
|
||||||
|
computeEnv?.id,
|
||||||
|
validUntil
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!algorithmOrderPriceAndFees) {
|
||||||
|
setError('Error setting algorithm price and fees!')
|
||||||
|
toast.error('Error setting algorithm price and fees!')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let algorithmOrderTx
|
let algorithmOrderTx
|
||||||
if (isAlgorithmOwned) {
|
if (isAlgorithmOwned) {
|
||||||
algorithmOrderTx = validAlgorithmOrderTx
|
algorithmOrderTx = validAlgorithmOrderTx
|
||||||
@ -274,6 +285,13 @@ export default function Compute({
|
|||||||
!hasAlgoAssetDatatoken &&
|
!hasAlgoAssetDatatoken &&
|
||||||
selectedAlgorithmAsset?.accessDetails?.type === 'dynamic'
|
selectedAlgorithmAsset?.accessDetails?.type === 'dynamic'
|
||||||
) {
|
) {
|
||||||
|
setComputeStatusText(
|
||||||
|
getComputeFeedback(
|
||||||
|
selectedAlgorithmAsset.accessDetails.baseToken?.symbol,
|
||||||
|
selectedAlgorithmAsset.accessDetails.datatoken?.symbol,
|
||||||
|
selectedAlgorithmAsset.metadata.type
|
||||||
|
)[1]
|
||||||
|
)
|
||||||
const tx = await buyDtFromPool(
|
const tx = await buyDtFromPool(
|
||||||
selectedAlgorithmAsset?.accessDetails,
|
selectedAlgorithmAsset?.accessDetails,
|
||||||
accountId,
|
accountId,
|
||||||
@ -285,14 +303,17 @@ export default function Compute({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LoggerInstance.log(
|
setComputeStatusText(
|
||||||
'algorithm orderPriceAndFees: ',
|
getComputeFeedback(
|
||||||
orderAlgorithmPriceAndFees
|
selectedAlgorithmAsset.accessDetails.baseToken?.symbol,
|
||||||
|
selectedAlgorithmAsset.accessDetails.datatoken?.symbol,
|
||||||
|
selectedAlgorithmAsset.metadata.type
|
||||||
|
)[selectedAlgorithmAsset.accessDetails?.type === 'fixed' ? 3 : 2]
|
||||||
)
|
)
|
||||||
const orderTx = await order(
|
const orderTx = await order(
|
||||||
web3,
|
web3,
|
||||||
selectedAlgorithmAsset,
|
selectedAlgorithmAsset,
|
||||||
orderAlgorithmPriceAndFees,
|
algorithmOrderPriceAndFees,
|
||||||
accountId,
|
accountId,
|
||||||
computeEnv?.id,
|
computeEnv?.id,
|
||||||
validUntil,
|
validUntil,
|
||||||
@ -327,6 +348,7 @@ export default function Compute({
|
|||||||
publishAlgorithmLog: true,
|
publishAlgorithmLog: true,
|
||||||
publishOutput: true
|
publishOutput: true
|
||||||
}
|
}
|
||||||
|
setComputeStatusText(getComputeFeedback()[4])
|
||||||
const response = await ProviderInstance.computeStart(
|
const response = await ProviderInstance.computeStart(
|
||||||
asset.services[0].serviceEndpoint,
|
asset.services[0].serviceEndpoint,
|
||||||
web3,
|
web3,
|
||||||
@ -410,7 +432,7 @@ export default function Compute({
|
|||||||
selectedAlgorithmAsset?.services[0]?.timeout
|
selectedAlgorithmAsset?.services[0]?.timeout
|
||||||
)}
|
)}
|
||||||
// lazy comment when removing pricingStepText
|
// lazy comment when removing pricingStepText
|
||||||
stepText={'pricingStepText' || 'Starting Compute Job...'}
|
stepText={computeStatusText}
|
||||||
isConsumable={isConsumable}
|
isConsumable={isConsumable}
|
||||||
consumableFeedback={consumableFeedback}
|
consumableFeedback={consumableFeedback}
|
||||||
/>
|
/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user