Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump ocean.js v0.16.2, ocean.assets.isConsumable implementation to disable buy button and display relevant message #463

Merged
merged 31 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1970e42
[KianYee] #452 Edit Metadata
kianyee Mar 29, 2021
6638810
[KianYee] #issue-452 Minor fix
kianyee Mar 30, 2021
843ca6f
add toggle consume var 'isDatasetConsumable'
krisliew Mar 30, 2021
8253cf9
Rename toggle consume var to 'isConsumeDisable'
krisliew Mar 30, 2021
e95de4d
Minor fix on metadata preview
krisliew Mar 30, 2021
0008b2d
Rename to isDisable
krisliew Apr 15, 2021
7d99156
[KianYee] #452 Edit Metadata
kianyee Mar 29, 2021
5f401dd
[KianYee] #issue-452 Minor fix
kianyee Mar 30, 2021
9874da8
add toggle consume var 'isDatasetConsumable'
krisliew Mar 30, 2021
1e49fcb
Rename toggle consume var to 'isConsumeDisable'
krisliew Mar 30, 2021
ef41e6c
Minor fix on metadata preview
krisliew Mar 30, 2021
1f34e0a
Rename to isDisable
krisliew Apr 15, 2021
83a339b
Merge branch 'feature/issues-452' of https://github.com/oceanprotocol…
krisliew Apr 15, 2021
3b5f20e
Merge branch 'main' into feature/issues-452
krisliew May 7, 2021
db11155
Merge branch 'main' into feature/issues-452
krisliew Jun 15, 2021
b3195e7
Remove old code, add status component
krisliew Jun 16, 2021
590aa27
remove old code
krisliew Jun 16, 2021
c4b4b20
Merge branch 'main' into feature/issues-452
krisliew Jun 16, 2021
321554d
use Consumable interface
krisliew Jun 16, 2021
72c7d42
feedback change
krisliew Jun 21, 2021
6efc45a
hotfix
krisliew Jun 21, 2021
c21711c
Merge branch 'main' into feature/issues-452
Jun 21, 2021
27faf44
feedback changes
krisliew Jun 28, 2021
0024201
Minor fix
krisliew Jun 28, 2021
6e90bd4
accountId from useWeb3() case sensitive fix
krisliew Jun 28, 2021
458f02a
Minor fix
krisliew Jun 28, 2021
9109454
Merge branch 'main' into feature/issues-452
Jul 1, 2021
1b27631
Update Ocean.js version, and minor fix
krisliew Jul 1, 2021
b1974db
Fix datePublished error on validate-remote
krisliew Jul 5, 2021
6cf684b
Squashed commit of the following:
krisliew Jul 5, 2021
9b86387
Merge branch 'main' into feature/issues-452
krisliew Jul 5, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@coingecko/cryptoformat": "^0.4.2",
"@loadable/component": "^5.15.0",
"@oceanprotocol/art": "^3.0.0",
"@oceanprotocol/lib": "^0.16.1",
"@oceanprotocol/lib": "^0.16.2",
"@oceanprotocol/typographies": "^0.1.0",
"@portis/web3": "^4.0.4",
"@sindresorhus/slugify": "^2.1.0",
Expand Down
52 changes: 40 additions & 12 deletions src/components/atoms/ButtonBuy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ interface ButtonBuyProps {
dtBalance: string
assetType: string
assetTimeout: string
isConsumable: boolean
consumableFeedback: string
hasPreviousOrderSelectedComputeAsset?: boolean
hasDatatokenSelectedComputeAsset?: boolean
dtSymbolSelectedComputeAsset?: string
Expand All @@ -23,20 +25,26 @@ interface ButtonBuyProps {
type?: 'submit'
priceType?: string
algorithmPriceType?: string
algorithmConsumableStatus?: number
}

function getConsumeHelpText(
dtBalance: string,
dtSymbol: string,
hasDatatoken: boolean,
hasPreviousOrder: boolean,
assetType: string
assetType: string,
isConsumable: boolean,
consumableFeedback: string
) {
const text = hasPreviousOrder
? `You bought this ${assetType} already allowing you to use it without paying again.`
: hasDatatoken
? `You own ${dtBalance} ${dtSymbol} allowing you to use this data set by spending 1 ${dtSymbol}, but without paying OCEAN again.`
: `For using this ${assetType}, you will buy 1 ${dtSymbol} and immediately spend it back to the publisher and pool.`
const text =
isConsumable === false
? consumableFeedback
: hasPreviousOrder
? `You bought this ${assetType} already allowing you to use it without paying again.`
: hasDatatoken
? `You own ${dtBalance} ${dtSymbol} allowing you to use this data set by spending 1 ${dtSymbol}, but without paying OCEAN again.`
: `For using this ${assetType}, you will buy 1 ${dtSymbol} and immediately spend it back to the publisher and pool.`

return text
}
Expand All @@ -47,22 +55,34 @@ function getComputeAssetHelpText(
dtSymbol: string,
dtBalance: string,
assetType: string,
isConsumable: boolean,
consumableFeedback: string,
hasPreviousOrderSelectedComputeAsset?: boolean,
hasDatatokenSelectedComputeAsset?: boolean,
dtSymbolSelectedComputeAsset?: string,
dtBalanceSelectedComputeAsset?: string,
selectedComputeAssetType?: string
selectedComputeAssetType?: string,
algorithmConsumableStatus?: number
) {
const computeAssetHelpText = getConsumeHelpText(
dtBalance,
dtSymbol,
hasDatatoken,
hasPreviousOrder,
assetType
assetType,
isConsumable,
consumableFeedback
)
const text =
!dtSymbolSelectedComputeAsset && !dtBalanceSelectedComputeAsset
(!dtSymbolSelectedComputeAsset && !dtBalanceSelectedComputeAsset) ||
isConsumable === false
? ''
: algorithmConsumableStatus === 1
? 'The selected algorithm has been temporarily disabled by the publisher, please try again later.'
: algorithmConsumableStatus === 2
? 'Access denied, your wallet address is not found on the selected algorithm allow list.'
: algorithmConsumableStatus === 3
? 'Access denied, your wallet address is found on the selected algorithm deny list.'
: hasPreviousOrderSelectedComputeAsset
? `You already bought the selected ${selectedComputeAssetType}, allowing you to use it without paying again.`
: hasDatatokenSelectedComputeAsset
Expand All @@ -81,6 +101,8 @@ export default function ButtonBuy({
dtBalance,
assetType,
assetTimeout,
isConsumable,
consumableFeedback,
hasPreviousOrderSelectedComputeAsset,
hasDatatokenSelectedComputeAsset,
dtSymbolSelectedComputeAsset,
Expand All @@ -91,7 +113,8 @@ export default function ButtonBuy({
isLoading,
type,
priceType,
algorithmPriceType
algorithmPriceType,
algorithmConsumableStatus
}: ButtonBuyProps): ReactElement {
const buttonText =
action === 'download'
Expand Down Expand Up @@ -127,19 +150,24 @@ export default function ButtonBuy({
dtSymbol,
hasDatatoken,
hasPreviousOrder,
assetType
assetType,
isConsumable,
consumableFeedback
)
: getComputeAssetHelpText(
hasPreviousOrder,
hasDatatoken,
dtSymbol,
dtBalance,
assetType,
isConsumable,
consumableFeedback,
hasPreviousOrderSelectedComputeAsset,
hasDatatokenSelectedComputeAsset,
dtSymbolSelectedComputeAsset,
dtBalanceSelectedComputeAsset,
selectedComputeAssetType
selectedComputeAssetType,
algorithmConsumableStatus
)}
</div>
</>
Expand Down
4 changes: 2 additions & 2 deletions src/components/molecules/FormFields/Credential/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export default function Credentials(props: InputProps) {
toast.error('Wallet address is invalid')
return
}
if (arrayInput.includes(value)) {
if (arrayInput.includes(value.toLowerCase())) {
toast.error('Wallet address already added into list')
return
}
setArrayInput((arrayInput) => [...arrayInput, value])
setArrayInput((arrayInput) => [...arrayInput, value.toLowerCase()])
setValue('')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { AssetSelectionAsset } from '../../../molecules/FormFields/AssetSelectio
import ButtonBuy from '../../../atoms/ButtonBuy'
import PriceOutput from './PriceOutput'
import { useAsset } from '../../../../providers/Asset'
import { useOcean } from '../../../../providers/Ocean'
import { useWeb3 } from '../../../../providers/Web3'

const contentQuery = graphql`
query StartComputeDatasetQuery {
Expand Down Expand Up @@ -58,7 +60,9 @@ export default function FormStartCompute({
selectedComputeAssetType,
selectedComputeAssetTimeout,
stepText,
algorithmPrice
algorithmPrice,
isConsumable,
consumableFeedback
}: {
algorithms: AssetSelectionAsset[]
ddoListAlgorithms: DDO[]
Expand All @@ -78,6 +82,8 @@ export default function FormStartCompute({
selectedComputeAssetTimeout?: string
stepText: string
algorithmPrice: BestPrice
isConsumable: boolean
consumableFeedback: string
}): ReactElement {
const data = useStaticQuery(contentQuery)
const content = data.content.edges[0].node.childPagesJson
Expand All @@ -86,6 +92,10 @@ export default function FormStartCompute({
useFormikContext()
const { price, ddo } = useAsset()
const [totalPrice, setTotalPrice] = useState(price?.value)
const { accountId } = useWeb3()
const { ocean } = useOcean()
const [algorithmConsumableStatus, setAlgorithmConsumableStatus] =
useState<number>()

function getAlgorithmAsset(algorithmId: string): DDO {
let assetDdo = null
Expand All @@ -97,8 +107,19 @@ export default function FormStartCompute({

useEffect(() => {
if (!values.algorithm) return
setSelectedAlgorithm(getAlgorithmAsset(values.algorithm))
}, [values.algorithm])
const algorithmDDO = getAlgorithmAsset(values.algorithm)
setSelectedAlgorithm(algorithmDDO)

if (!accountId || !isConsumable) return
async function checkIsConsumable() {
const consumable = await ocean.assets.isConsumable(
algorithmDDO,
accountId.toLowerCase()
)
if (consumable) setAlgorithmConsumableStatus(consumable.status)
}
checkIsConsumable()
}, [values.algorithm, accountId, isConsumable])

//
// Set price for calculation output
Expand Down Expand Up @@ -149,7 +170,9 @@ export default function FormStartCompute({

<ButtonBuy
action="compute"
disabled={isComputeButtonDisabled || !isValid}
disabled={
isComputeButtonDisabled || !isValid || algorithmConsumableStatus > 0
}
hasPreviousOrder={hasPreviousOrder}
hasDatatoken={hasDatatoken}
dtSymbol={ddo.dataTokenInfo.symbol}
Expand All @@ -168,6 +191,9 @@ export default function FormStartCompute({
type="submit"
priceType={price?.type}
algorithmPriceType={algorithmPrice?.type}
isConsumable={isConsumable}
consumableFeedback={consumableFeedback}
algorithmConsumableStatus={algorithmConsumableStatus}
/>
</Form>
)
Expand Down
14 changes: 12 additions & 2 deletions src/components/organisms/AssetActions/Compute/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ export default function Compute({
isBalanceSufficient,
dtBalance,
file,
fileIsLoading
fileIsLoading,
isConsumable,
consumableFeedback
}: {
isBalanceSufficient: boolean
dtBalance: string
file: FileMetadata
fileIsLoading?: boolean
isConsumable?: boolean
consumableFeedback?: string
}): ReactElement {
const { appConfig } = useSiteMetadata()
const { accountId } = useWeb3()
Expand All @@ -82,7 +86,11 @@ export default function Compute({
const [algorithmTimeout, setAlgorithmTimeout] = useState<string>()

const isComputeButtonDisabled =
isJobStarting === true || file === null || !ocean || !isBalanceSufficient
isJobStarting === true ||
file === null ||
!ocean ||
!isBalanceSufficient ||
!isConsumable
const hasDatatoken = Number(dtBalance) >= 1

async function checkPreviousOrders(ddo: DDO) {
Expand Down Expand Up @@ -420,6 +428,8 @@ export default function Compute({
selectedComputeAssetTimeout={algorithmTimeout}
stepText={pricingStepText || 'Starting Compute Job...'}
algorithmPrice={algorithmPrice}
isConsumable={isConsumable}
consumableFeedback={consumableFeedback}
/>
</Formik>
)}
Expand Down
32 changes: 20 additions & 12 deletions src/components/organisms/AssetActions/Consume.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ export default function Consume({
file,
isBalanceSufficient,
dtBalance,
fileIsLoading
fileIsLoading,
isConsumable,
consumableFeedback
}: {
ddo: DDO
file: FileMetadata
isBalanceSufficient: boolean
dtBalance: string
fileIsLoading?: boolean
isConsumable?: boolean
consumableFeedback?: string
}): ReactElement {
const { accountId } = useWeb3()
const { ocean } = useOcean()
Expand All @@ -56,7 +60,7 @@ export default function Consume({
const { consumeStepText, consume, consumeError, isLoading } = useConsume()
const [isDisabled, setIsDisabled] = useState(true)
const [hasDatatoken, setHasDatatoken] = useState(false)
const [isConsumable, setIsConsumable] = useState(true)
const [isConsumablePrice, setIsConsumablePrice] = useState(true)
const [assetTimeout, setAssetTimeout] = useState('')
const { data } = useQuery<OrdersData>(previousOrderQuery, {
variables: {
Expand Down Expand Up @@ -94,7 +98,7 @@ export default function Consume({
useEffect(() => {
if (!price) return

setIsConsumable(
setIsConsumablePrice(
price.isConsumable !== undefined ? price.isConsumable === 'true' : true
)
}, [price])
Expand All @@ -105,22 +109,24 @@ export default function Consume({

useEffect(() => {
setIsDisabled(
(!ocean ||
!isBalanceSufficient ||
typeof consumeStepText !== 'undefined' ||
pricingIsLoading ||
!isConsumable) &&
!hasPreviousOrder &&
!hasDatatoken
!isConsumable ||
((!ocean ||
!isBalanceSufficient ||
typeof consumeStepText !== 'undefined' ||
pricingIsLoading ||
!isConsumablePrice) &&
!hasPreviousOrder &&
!hasDatatoken)
)
}, [
ocean,
hasPreviousOrder,
isBalanceSufficient,
consumeStepText,
pricingIsLoading,
isConsumable,
hasDatatoken
isConsumablePrice,
hasDatatoken,
isConsumable
])

async function handleConsume() {
Expand Down Expand Up @@ -161,6 +167,8 @@ export default function Consume({
stepText={consumeStepText || pricingStepText}
isLoading={pricingIsLoading || isLoading}
priceType={price?.type}
isConsumable={isConsumable}
consumableFeedback={consumableFeedback}
/>
)

Expand Down
Loading