diff --git a/CHANGELOG.md b/CHANGELOG.md index 919a044..dc84ff7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,22 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +#### [v1.7.0-rc1](https://github.com/nevermined-io/components-catalog/compare/v1.6.5...v1.7.0-rc1) + +> 13 June 2023 + +- pass account by argument instead of get from the list [`4c663e9`](https://github.com/nevermined-io/components-catalog/commit/4c663e922bada1cb26d10adbbc39586379711979) +- fix doc lint issues [`0c66736`](https://github.com/nevermined-io/components-catalog/commit/0c66736dd2feb0233c80775e8561441b2ba1c78d) +- addresss comment [`bac396d`](https://github.com/nevermined-io/components-catalog/commit/bac396d8801ca378515ec21e8b719d600194cee1) + +#### [v1.6.5](https://github.com/nevermined-io/components-catalog/compare/v1.6.4...v1.6.5) + +> 2 June 2023 + +- set different search options [`#304`](https://github.com/nevermined-io/components-catalog/pull/304) +- improvements in search subscriptions [`d7e1262`](https://github.com/nevermined-io/components-catalog/commit/d7e12623c91bbb73499bbe1bc1ced72c1bfed1c8) +- Adding v1.6.4 Changelog updates [`9a0b0eb`](https://github.com/nevermined-io/components-catalog/commit/9a0b0eba69cdaa6c72a2669bd1c098519cbb6ab7) + #### [v1.6.4](https://github.com/nevermined-io/components-catalog/compare/v1.6.3...v1.6.4) > 1 June 2023 diff --git a/catalog/integration-tests/catalog-dtp.spec.tsx b/catalog/integration-tests/catalog-dtp.spec.tsx index a04f42b..50fdc31 100644 --- a/catalog/integration-tests/catalog-dtp.spec.tsx +++ b/catalog/integration-tests/catalog-dtp.spec.tsx @@ -77,6 +77,7 @@ describe('DTP', () => { (async () => { const result = await publishNFT1155({ + publisher, nftAttributes, password, cryptoConfig, @@ -128,11 +129,11 @@ describe('DTP', () => { try { const result = await nfts.access({ did: ddoResult.id, + buyer: consumer, nftHolder: publisher.getId(), nftAmount: BigNumber.from(1), ercType: 1155, password, - accountIndex: 1 }) setAgreementId(result) @@ -171,7 +172,7 @@ describe('DTP', () => { (async () => { try { - const result = await assets.downloadNFT({did: ddoResult.id, ercType: 1155, path: undefined, fileIndex: 1, password, accountIndex: 1}) as string + const result = await assets.downloadNFT({did: ddoResult.id, consumer, ercType: 1155, path: undefined, fileIndex: 1, password}) as string setIsDownloaded(result) } catch (error: any) { console.error(error.message) diff --git a/catalog/package.json b/catalog/package.json index 6d31fbb..0c984a6 100644 --- a/catalog/package.json +++ b/catalog/package.json @@ -1,6 +1,6 @@ { "name": "@nevermined-io/catalog", - "version": "1.6.6", + "version": "1.7.0", "main": "./dist/index.js", "types": "./dist/index.d.ts", "dependencies": { diff --git a/catalog/src/catalog.tsx b/catalog/src/catalog.tsx index a5355dd..279d6a5 100644 --- a/catalog/src/catalog.tsx +++ b/catalog/src/catalog.tsx @@ -28,7 +28,6 @@ import { } from './types' import { conductOrder, - getCurrentAccount, isEmptyObject, loadFulfilledEvents, getAgreementId, @@ -40,6 +39,8 @@ import { } from './utils' import { _getCryptoConfig, _getDTPInstance, _grantAccess } from './utils/dtp' import { getAddressTokenSigner, isTokenValid, newMarketplaceApiToken } from './utils/marketplace_token' +import { TransferError } from './exceptions/transfer-exception' +import { LockPaymentError } from './exceptions/lockpayment-exceptions' const initialState = { sdk: {} as Nevermined @@ -157,8 +158,8 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv const account: AccountModule = { isTokenValid: (): boolean => isTokenValid(), getAddressTokenSigner: (): string => String(getAddressTokenSigner()), - generateToken: async (): Promise => { - const tokenData = await newMarketplaceApiToken(sdk) + generateToken: async (account: Account): Promise => { + const tokenData = await newMarketplaceApiToken(sdk, account) if(!tokenData.token) { return { token: '' @@ -217,9 +218,8 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv } }, - getPublishedSubscriptions: async (searchOptions?: SearchOptions): Promise => { + getPublishedSubscriptions: async (account: Account, searchOptions?: SearchOptions): Promise => { try { - const account = await getCurrentAccount(sdk) const query = await sdk.search.subscriptionsCreated(account, searchOptions?.customNestedQueries, searchOptions?.offset, searchOptions?.page, searchOptions?.sort, searchOptions?.appId) return query } catch (error) { @@ -229,11 +229,11 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv }, getPublishedSubscriptionsAndServices: async ( + account: Account, searchOptionsSubscriptions?: SearchOptions, searchOptionsServices?: SearchOptions ): Promise => { try { - const account = await getCurrentAccount(sdk) const query = await sdk.search.subscriptionsCreated(account, searchOptionsSubscriptions?.customNestedQueries, searchOptionsSubscriptions?.offset, searchOptionsSubscriptions?.page, searchOptionsSubscriptions?.sort, searchOptionsSubscriptions?.appId) return getSubscriptionsAndServices(query.results, sdk, searchOptionsServices) } catch (error) { @@ -243,11 +243,11 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv }, getPublishedSubscriptionsAndDatasets: async ( + account: Account, searchOptionsSubscriptions?: SearchOptions, searchOptionsDatasets?: SearchOptions ): Promise => { try { - const account = await getCurrentAccount(sdk) const query = await sdk.search.subscriptionsCreated(account, searchOptionsSubscriptions?.customNestedQueries, searchOptionsSubscriptions?.offset, searchOptionsSubscriptions?.page, searchOptionsSubscriptions?.sort, searchOptionsSubscriptions?.appId) return getSubscriptionsAndDatasets(query.results, sdk, searchOptionsDatasets) } catch (error) { @@ -256,9 +256,8 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv } }, - getPurchasedSubscriptions: async (searchOptions?: SearchOptions): Promise => { + getPurchasedSubscriptions: async (account: Account, searchOptions?: SearchOptions): Promise => { try { - const account = await getCurrentAccount(sdk) const query = await sdk.search.subscriptionsPurchased(account, searchOptions?.customNestedQueries, searchOptions?.offset, searchOptions?.page, searchOptions?.sort, searchOptions?.appId) return query } catch (error) { @@ -268,11 +267,11 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv }, getPurchasedSubscriptionsAndServices: async ( + account: Account, searchOptionsSubscriptions?: SearchOptions, searchOptionsServices?: SearchOptions ): Promise => { try { - const account = await getCurrentAccount(sdk) const query = await sdk.search.subscriptionsPurchased(account, searchOptionsSubscriptions?.customNestedQueries, searchOptionsSubscriptions?.offset, searchOptionsSubscriptions?.page, searchOptionsSubscriptions?.sort, searchOptionsSubscriptions?.appId) return getSubscriptionsAndServices(query.results, sdk, searchOptionsServices) } catch (error) { @@ -282,11 +281,11 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv }, getPurchasedSubscriptionsAndDatasets: async ( + account: Account, searchOptionsSubscriptions?: SearchOptions, searchOptionsDatasets?: SearchOptions ): Promise => { try { - const account = await getCurrentAccount(sdk) const query = await sdk.search.subscriptionsPurchased(account, searchOptionsSubscriptions?.customNestedQueries, searchOptionsSubscriptions?.offset, searchOptionsSubscriptions?.page, searchOptionsSubscriptions?.sort, searchOptionsSubscriptions?.appId) return getSubscriptionsAndDatasets(query.results, sdk, searchOptionsDatasets) } catch (error) { @@ -381,14 +380,13 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv } }, - transfer: async ({ did, amount, ercType }: { did: string; amount: number; ercType?: ERCType }): Promise => { + transfer: async ({ did, amount, ercType, newOwner, }: { did: string; amount: number; ercType?: ERCType, newOwner: Account; }): Promise => { try { if (!config.neverminedNodeAddress || !config.neverminedNodeUri) { Logger.log('neverminedNodeAddress or neverminedNodeUri is not set. Abort.') return false } const transferEndpoint = `${config.neverminedNodeUri}/api/v1/node/services/nft-transfer` - const [newOwner] = await sdk.accounts.list() if (!newOwner) { Logger.log('Users need to be connected to perform a transfer. abort.') return false @@ -431,19 +429,17 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv } }, - orderAsset: async (did: string): Promise => { - const account = await getCurrentAccount(sdk) - + orderAsset: async (did: string, consumerAccount: Account): Promise => { const owner = await sdk.assets.owner(did) - if (owner === account.getId()) { + if (owner === consumerAccount.getId()) { throw new ClientError( "You are already the owner, you don't need to order the asset", 'Catalog' ) } - const purchased = await loadFulfilledEvents(sdk, account.getId(), 'accessCondition') + const purchased = await loadFulfilledEvents(sdk, consumerAccount.getId(), 'accessCondition') const purchasedDDO = await Promise.all( purchased.map((asset) => sdk.assets.resolve(asset.documentId)) @@ -455,31 +451,27 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv return getAgreementId(sdk, 'accessTemplate', did) } - return sdk.assets.order(did, account) + return sdk.assets.order(did, consumerAccount) }, - orderNFT1155: async (did: string, amount: BigNumber): Promise => { - const account = await getCurrentAccount(sdk) - - const balance = await sdk.nfts1155.balance(did, account) + orderNFT1155: async (did: string, amount: BigNumber, consumer: Account): Promise => { + const balance = await sdk.nfts1155.balance(did, consumer) if (BigNumber.from(balance).toNumber() > 0) { return getAgreementId(sdk, 'nftAccessTemplate', did) } - return sdk.nfts1155.order(did, amount, account) + return sdk.nfts1155.order(did, amount, consumer) }, - orderNFT721: async (did: string): Promise => { - const account = await getCurrentAccount(sdk) - + orderNFT721: async (did: string, consumer: Account): Promise => { const holder = await sdk.nfts721.ownerOf(did) - if (holder === account.getId()) { + if (holder === consumer.getId()) { return getAgreementId(sdk, 'nft721AccessTemplate', did) } - return sdk.nfts721.order(did, account) + return sdk.nfts721.order(did, consumer) }, nftDetails: async (did: string, ercType: ERCType): Promise => { @@ -498,37 +490,36 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv password, path, fileIndex, - accountIndex + consumer, }: { did: string, ercType?: ERCType, path?: string, fileIndex?: number, password?: string, - accountIndex?: number + consumer: Account, }): Promise => { try { - const account = await getCurrentAccount(sdk, accountIndex) if(password) { const cryptoConfig = await _getCryptoConfig(sdk, password) const dtp = await _getDTPInstance(sdk, config, cryptoConfig) - const consumer = await _grantAccess({ + const consumerDtp = await _grantAccess({ did, - account, + account: consumer, password, sdk, dtp, }) as Account - const response = await sdk.assets.download(did, consumer, path, fileIndex, 'nft-sales-proof') + const response = await sdk.assets.download(did, consumerDtp, path, fileIndex, 'nft-sales-proof') return Boolean(response) } return ercType === 721 - ? sdk.nfts721.access(did, account, path, fileIndex) as Promise - : sdk.nfts1155.access(did, account, path, fileIndex) as Promise + ? sdk.nfts721.access(did, consumer, path, fileIndex) as Promise + : sdk.nfts1155.access(did, consumer, path, fileIndex) as Promise } catch (error) { verbose && Logger.error(error) return false @@ -540,57 +531,54 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv fileIndex, path, password, - accountIndex + consumer, }: { did: string, fileIndex?: number, path?: string, password?: string, - accountIndex?: number + consumer: Account, }): Promise => { try { - const account = await getCurrentAccount(sdk, accountIndex) - const agreementId = await getAgreementId(sdk, 'accessTemplate', did) if(password && agreementId) { const cryptoConfig = await _getCryptoConfig(sdk, password) const dtp = await _getDTPInstance(sdk, config, cryptoConfig) - const consumer = await _grantAccess({ + const consumerDtp = await _grantAccess({ did, - account, + account: consumer, password, sdk, dtp, }) as Account - const response = await sdk.assets.download(did, consumer, path, fileIndex, 'nft-sales-proof') + const response = await sdk.assets.download(did, consumerDtp, path, fileIndex, 'nft-sales-proof') return Boolean(response) } - if ((await sdk.assets.owner(did)) === account.getId()) { - const response = await sdk.assets.download(did, account, path, fileIndex) + if ((await sdk.assets.owner(did)) === consumer.getId()) { + const response = await sdk.assets.download(did, consumer, path, fileIndex) return Boolean(response) } - return sdk.assets.access(agreementId, did, account, path, fileIndex) as Promise + return sdk.assets.access(agreementId, did, consumer, path, fileIndex) as Promise } catch (error) { verbose && Logger.error(error) return false } }, - getCustomErc20Token: async (customErc20TokenAddress: string) => { + getCustomErc20Token: async (customErc20TokenAddress: string, address: string) => { const customErc20Token = await sdk.contracts.loadErc20(customErc20TokenAddress) - const account = await getCurrentAccount(sdk) return { name: await customErc20Token.name(), symbol: await customErc20Token.symbol(), decimals: await customErc20Token.decimals(), - balance: await customErc20Token.balanceOf(account.getId()) + balance: await customErc20Token.balanceOf(address) } }, @@ -657,28 +645,26 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv nftAmount, ercType, password, - accountIndex, onEvent, + buyer, }: { - did: string + did: string, nftHolder: string nftAmount: BigNumber ercType?: ERCType password?: string - accountIndex?: number + buyer: Account, onEvent?: (next: OrderProgressStep) => void }): Promise => { - let agreementId + let agreementId = '' let transferResult try { - const buyer = await getCurrentAccount(sdk, accountIndex) - if (!account.isTokenValid() || account.getAddressTokenSigner().toLowerCase() !== buyer.getId().toLowerCase()) { Logger.error( 'Your login is expired or not valid' ) - await account.generateToken() + await account.generateToken(buyer) } if(password) { @@ -697,13 +683,15 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv transferResult = await dtp.transferForDelegate(did, agreementId, consumer, nftAmount, nftHolder) } else { + agreementId = await executeWithProgressEvent( () => ercType === 721 ? sdk.nfts721.order(did, buyer) : sdk.nfts1155.order(did, BigNumber.from(nftAmount), buyer), onEvent, - ) + ) + transferResult = ercType === 721 ? await sdk.nfts721.claim( @@ -718,15 +706,21 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv buyer.getId(), nftAmount, did - ) + ) + + if(!transferResult) { + throw new Error(`Error claiming the NFT of the subscription with agreement ${agreementId}`) } - } catch (error) { + } + } catch(error) { verbose && Logger.error(error) - throw error - } + if(!agreementId) { + throw new LockPaymentError((error as Error).message) + } - if (!transferResult) - throw new Error("Error delegating the NFT of the subscription with agreement " + agreementId) + throw new TransferError(agreementId, (error as Error).message) + + } return agreementId }, diff --git a/catalog/src/exceptions/lockpayment-exceptions.ts b/catalog/src/exceptions/lockpayment-exceptions.ts new file mode 100644 index 0000000..a302516 --- /dev/null +++ b/catalog/src/exceptions/lockpayment-exceptions.ts @@ -0,0 +1,5 @@ +export class LockPaymentError extends Error { + constructor(message: string) { + super(`Lock payment error: ${message}`) + } +} diff --git a/catalog/src/exceptions/transfer-exception.ts b/catalog/src/exceptions/transfer-exception.ts new file mode 100644 index 0000000..9c60053 --- /dev/null +++ b/catalog/src/exceptions/transfer-exception.ts @@ -0,0 +1,8 @@ +export class TransferError extends Error { + public agreementId: string + + constructor(aggreementId: string, message: string) { + super(`Transfer error: ${message}`) + this.agreementId = aggreementId + } +} diff --git a/catalog/src/services/account.ts b/catalog/src/services/account.ts index a09fa2f..d30430c 100644 --- a/catalog/src/services/account.ts +++ b/catalog/src/services/account.ts @@ -345,14 +345,14 @@ export const useUserProfile = ( const [addresses, setAddresses] = useState([]) const [reloadTrigger, setReloadTrigger] = useState() - const checkAuth = async () => { + const checkAuth = async (userAccount: Account) => { let tokenObject = { token: '' } if (!account.isTokenValid()) { setIsTokenGenerated(false) setErrorMessage( 'Your login is expired. Please first sign with your wallet before to continue', ) - tokenObject = await account.generateToken() + tokenObject = await account.generateToken(userAccount) setIsTokenGenerated(Boolean(tokenObject.token)) } else { tokenObject = fetchMarketplaceApiTokenFromLocalStorage() @@ -387,7 +387,8 @@ export const useUserProfile = ( const submitUserProfile = async () => { try { - await checkAuth() + const userAccount = await sdk.accounts.getAccount(walletAddress) + await checkAuth(userAccount) if (!userProfile.nickname) { setInputError('Nickname is required') @@ -428,6 +429,8 @@ export const useUserProfile = ( return } + const userAccount = await sdk.accounts.getAccount(walletAddress) + setUserProfileLoadingStatus('loading') const userProfileData = await sdk.services.profiles.findOneByAddress(walletAddress) @@ -437,7 +440,7 @@ export const useUserProfile = ( setNewAddress('') } - const tokenAuth = await checkAuth() + const tokenAuth = await checkAuth(userAccount) setAddresses([...userProfileData.addresses]) @@ -457,7 +460,8 @@ export const useUserProfile = ( setNewAddress(walletAddress) setUserProfileLoadingStatus('failed') } else if (error.message.includes('"statusCode":404')) { - await account.generateToken() + const userAccount = await sdk.accounts.getAccount(walletAddress) + await account.generateToken(userAccount) setTimeout(async () => { try { const userProfileData = await sdk.services.profiles.findOneByAddress(walletAddress) diff --git a/catalog/src/services/asset.tsx b/catalog/src/services/asset.tsx index b64cdff..2079ac9 100644 --- a/catalog/src/services/asset.tsx +++ b/catalog/src/services/asset.tsx @@ -17,8 +17,9 @@ import { ERCType, CryptoConfig, CreateProgressStep, + Account, } from '../types' -import { executeWithProgressEvent, getCurrentAccount } from '../utils' +import { executeWithProgressEvent } from '../utils' import {_getDTPInstance, _encryptFileMetadata} from '../utils/dtp' /** @@ -173,6 +174,7 @@ export const AssetPublishProvider = ({ children }: { children: React.ReactElemen * @param asset.method Method used to encrypt the urls * @param asset.password Password to encrypt metadata * @param asset.onEvent A callback to handle progress events + * @param asset.publisher The user account * @returns The DDO object including the asset metadata and the DID */ const publishAsset = async ({ @@ -182,6 +184,7 @@ export const AssetPublishProvider = ({ children }: { children: React.ReactElemen password, cryptoConfig, onEvent, + publisher, }: { assetAttributes: AssetAttributes; @@ -190,18 +193,17 @@ export const AssetPublishProvider = ({ children }: { children: React.ReactElemen password?: string, cryptoConfig?: CryptoConfig, onEvent?: (next: CreateProgressStep) => void, + publisher: Account }) => { try { setIsProcessing(true) - const accountWallet = await getCurrentAccount(sdk) - - if (!account.isTokenValid() || account.getAddressTokenSigner().toLowerCase() !== accountWallet.getId().toLowerCase()) { + if (!account.isTokenValid() || account.getAddressTokenSigner().toLowerCase() !== publisher.getId().toLowerCase()) { Logger.error( 'Your login is expired or not valid' ) - await account.generateToken() + await account.generateToken(publisher) } if (password) { @@ -212,7 +214,7 @@ export const AssetPublishProvider = ({ children }: { children: React.ReactElemen const ddo = await executeWithProgressEvent(() => sdk.assets.create( assetAttributes, - accountWallet, + publisher, publishMetadata, txParameters, ), onEvent) @@ -246,6 +248,7 @@ export const AssetPublishProvider = ({ children }: { children: React.ReactElemen * @param nft721.method Method used to encrypt the urls * @param nft721.password Password to encrypt metadata * @param nft721.onEvent A callback to handle progress events + * @param nft721.publisher The user account* * @returns The DDO object including the asset metadata and the DID */ const publishNFT721 = async ({ @@ -256,6 +259,7 @@ export const AssetPublishProvider = ({ children }: { children: React.ReactElemen password, cryptoConfig, onEvent, + publisher }: { nftAttributes: NFTAttributes; @@ -264,18 +268,17 @@ export const AssetPublishProvider = ({ children }: { children: React.ReactElemen txParameters?: TxParameters, password?: string, cryptoConfig?: CryptoConfig, - onEvent?: (next: CreateProgressStep) => void + onEvent?: (next: CreateProgressStep) => void, + publisher: Account }) => { try { setIsProcessing(true) - const accountWallet = await getCurrentAccount(sdk) - - if (!account.isTokenValid() || account.getAddressTokenSigner().toLowerCase() !== accountWallet.getId().toLowerCase()) { + if (!account.isTokenValid() || account.getAddressTokenSigner().toLowerCase() !== publisher.getId().toLowerCase()) { setErrorAssetMessage( 'Your login is expired. Please first sign with your wallet and after try again' ) - await account.generateToken() + await account.generateToken(publisher) } if (password) { @@ -288,7 +291,7 @@ export const AssetPublishProvider = ({ children }: { children: React.ReactElemen const ddo = await executeWithProgressEvent(() => sdk.nfts721.create( nftAttributes, - accountWallet, + publisher, publishMetadata, txParameters, ), onEvent) @@ -329,6 +332,7 @@ export const AssetPublishProvider = ({ children }: { children: React.ReactElemen * @param nft1155.appId The id of the application creating the NFT * @param nft1155.txParameters Trasaction number of the asset creation * @param nft1155.onEvent A callback to handle progress events + * @param nft1155.publisher The user account * @returns The DDO object including the asset metadata and the DID */ const publishNFT1155 = async ({ @@ -338,6 +342,7 @@ export const AssetPublishProvider = ({ children }: { children: React.ReactElemen password, cryptoConfig, onEvent, + publisher }: { nftAttributes: NFTAttributes; @@ -346,17 +351,16 @@ export const AssetPublishProvider = ({ children }: { children: React.ReactElemen password?: string, cryptoConfig?: CryptoConfig, onEvent?: (next: CreateProgressStep) => void, + publisher: Account; }) => { try { setIsProcessing(true) - const accountWallet = await getCurrentAccount(sdk) - - if (!account.isTokenValid() || account.getAddressTokenSigner().toLowerCase() !== accountWallet.getId().toLowerCase()) { + if (!account.isTokenValid() || account.getAddressTokenSigner().toLowerCase() !== publisher.getId().toLowerCase()) { setErrorAssetMessage( 'Your login is expired. Please first sign with your wallet and after try again' ) - await account.generateToken() + await account.generateToken(publisher) } if (!config.neverminedNodeAddress) { @@ -372,7 +376,7 @@ export const AssetPublishProvider = ({ children }: { children: React.ReactElemen const ddo = await executeWithProgressEvent(() => sdk.nfts1155.create( nftAttributes, - accountWallet, + publisher, publishMetadata, txParameters ), onEvent) diff --git a/catalog/src/types/index.ts b/catalog/src/types/index.ts index 62c1b29..76b8061 100644 --- a/catalog/src/types/index.ts +++ b/catalog/src/types/index.ts @@ -19,6 +19,7 @@ import { RoyaltyKind, OrderProgressStep, MetaDataExternalResource, + Account, } from '@nevermined-io/sdk' import { CryptoConfig } from '@nevermined-io/sdk-dtp' @@ -425,7 +426,10 @@ export interface AccountModule { * @param searchOptions options for customize result * @returns published subscriptions */ - getPublishedSubscriptions: (searchOptions?: SearchOptions) => Promise + getPublishedSubscriptions: ( + account: Account, + searchOptions?: SearchOptions, + ) => Promise /** * Get all the services associated a subscription * @param address the subscription address @@ -442,55 +446,69 @@ export interface AccountModule { getAssociatedDatasets: (did: string, searchOptions?: SearchOptions) => Promise /** * Get all the published subscriptions and services associated from the wallet address passed + * @param account Account of the user * @param searchOptionsSubscriptions options for customize result of Subscriptions * @param searchOptionsServices options for customize result of Service * @returns published subscriptions and service */ getPublishedSubscriptionsAndServices: ( + account: Account, searchOptionsSubscriptions?: SearchOptions, searchOptionsServices?: SearchOptions, ) => Promise /** * Get all the published subscriptions and datasets associated from the wallet address passed + * @param account Account of the user * @param searchOptionsSubscriptions options for customize result of Subscriptions * @param searchOptionsDatasets options for customize result of Datasets * @returns published subscriptions and its datasets */ getPublishedSubscriptionsAndDatasets: ( + account: Account, searchOptionsSubscriptions?: SearchOptions, searchOptionsDatasets?: SearchOptions, ) => Promise /** * Get only purchased Subscriptions + * @param account Account of the user * @param searchOptions options for customize result + * * @returns purchased subscriptions */ - getPurchasedSubscriptions: (searchOptions?: SearchOptions) => Promise + getPurchasedSubscriptions: ( + account: Account, + searchOptions?: SearchOptions, + ) => Promise /** * Get all the purchased subscriptions and services associated from the wallet address passed + * @param account Account of the user * @param searchOptionsSubscriptions options for customize result of Subscriptions * @param searchOptionsServices options for customize result of Service * @returns purchased subscriptions and services */ getPurchasedSubscriptionsAndServices: ( + account: Account, searchOptionsSubscriptions?: SearchOptions, searchOptionsServices?: SearchOptions, ) => Promise /** * Get all the purchased subscriptions and datasets associated from the wallet address passed + * @param account Account of the user * @param searchOptionsSubscriptions options for customize result of Subscriptions * @param searchOptionsDatasets options for customize result of Datasets * @returns purchased subscriptions and its datasets */ getPurchasedSubscriptionsAndDatasets: ( + account: Account, searchOptionsSubscriptions?: SearchOptions, searchOptionsDatasets?: SearchOptions, ) => Promise /** * Generate a token for authentication in the Marketplace API + * @param account Account of the user * @returns The new generated token */ - generateToken: () => Promise + generateToken: (account: Account) => Promise /** * check if the token for Marketplace API is valid * @returns if token is valid it will return true @@ -553,16 +571,19 @@ export interface AssetsModule { * @param assetInfo.did The id of the asset * @param assetInfo.amount The amount of asset to transfer * @param assetInfo.ercType NFT asset type which can be 721 or 1155 + * @param assetInfo.newOwner Account of the owner * @returns Return true if asset was transferred successfully */ transfer: ({ did, amount, ercType, + newOwner, }: { did: string amount: number ercType: ERCType + newOwner: Account }) => Promise /** * Get the aggreement details of the NFT asset (owner, nfts supplay, royalties, etc...) @@ -574,26 +595,29 @@ export interface AssetsModule { /** * This method order a asset to allow after transfer to the buyer (the method only order but not transfer) * @param did id of the asset + * @param consumer Account of the consumer * @returns In case the order is completed successfully it returns the agreementId * which is needed to transfer the asset to the buyer */ - orderAsset: (did: string) => Promise + orderAsset: (did: string, consumer: Account) => Promise /** * This method order a NFT721 asset to allow after transfer to the buyer (the method only order but not transfer) * @param did id of the NFT721 asset + * @param account Account of the user * @param amount Amount of NFT721 assets to order * @returns In case the order is completed successfully it returns the agreementId * which is needed to transfer the NFT721 asset to the buyer */ - orderNFT721: (did: string, nftTokenAddress: string) => Promise + orderNFT721: (did: string, consumer: Account, nftTokenAddress: string) => Promise /** * This method order a NFT1155 asset to allow after transfer to the buyer (the method only order but not transfer) * @param did id of the NFT1155 asset * @param amount Amount of NFT1155 assets to order + * @param consumer Account of the consumer * @returns In case the order is completed successfully it returns the agreementId * which is needed to transfer the NFT1155 asset to the buyer */ - orderNFT1155: (did: string, amount: BigNumber) => Promise + orderNFT1155: (did: string, amount: BigNumber, consumer: Account) => Promise /** * Download a NFT asset already ordered and transfered to the buyer, * if the user is the owner of the asset @@ -603,7 +627,7 @@ export interface AssetsModule { * @param nft.path Destination of downloaded file * @param nft.fileIndex The file to download. If not given or is -1 it will download all of them * @param nft.password Password to download a encrypted NFT - * @param nft.accountIndex account index of the account list wallet, it is used for testing purpose + * @param nft.consumer Account of the consumer * @returns if the NFT is downloaded successfully the method will return a true */ downloadNFT: ({ @@ -612,21 +636,25 @@ export interface AssetsModule { path, fileIndex, password, - accountIndex, + consumer, }: { did: string ercType?: ERCType path?: string fileIndex?: number password?: string - accountIndex?: number + consumer: Account }) => Promise /** * Get all the details about a custom erc20 token * @param customErc20TokenAddress The custom token address + * @param address Wallet address of the user * @returns Custom token details */ - getCustomErc20Token: (customErc20TokenAddress: string) => Promise + getCustomErc20Token: ( + customErc20TokenAddress: string, + address: string, + ) => Promise /** * Download an asset already ordered and transfered to the buyer, * if the user is the owner of the asset @@ -635,7 +663,7 @@ export interface AssetsModule { * @param asset.path Destination of downloaded file * @param asset.fileIndex The file to download. If not given or is -1 it will download all of them * @param asset.password Password to download a encrypted NFT - * @param asset.accountIndex account index of the account list wallet, it is used for testing purpose + * @param asset.consumer Account of the consumer * @returns if the NFT is downloaded successfully the method will return a true */ downloadAsset: ({ @@ -643,13 +671,13 @@ export interface AssetsModule { fileIndex, path, password, - accountIndex, + consumer, }: { did: string fileIndex?: number path?: string password?: string - accountIndex?: number + consumer: Account }) => Promise /** * Upload files to Filecoin @@ -836,28 +864,28 @@ export interface NFTSModule { * @param access * @param access.did Id of the NFT to subscribe * @param access.nftHolder The owner of the NFT asset + * @param access.buyer Account of the buyer * @param access.nftAmount The amount of NFT asset to buy * @param access.ercType NFT asset type which can be `721` or `1155` * @param access.password Password to desencrypt metadata - * @param access.accountIndex account index of the account list wallet, it is used for testing purpose * @param asset.onEvent A callback to handle progress events * @returns It is successfully completed will return the `agreementId` */ access: ({ did, nftHolder, + buyer, nftAmount, ercType, password, - accountIndex, onEvent, }: { did: string nftHolder: string + buyer: Account nftAmount: BigNumber ercType: ERCType password?: string - accountIndex?: number onEvent?: (next: OrderProgressStep) => void }) => Promise } @@ -904,6 +932,7 @@ export interface AssetPublishProviderState { * @param asset.password Password to encrypt metadata * @param asset.cryptoConfig Setting for encrypting asset * @param asset.onEvent A callback to handle progress events + * @param asset.publisher Account of the publisher * @returns The DDO object including the asset metadata and the DID */ publishAsset: ({ @@ -913,6 +942,7 @@ export interface AssetPublishProviderState { password, cryptoConfig, onEvent, + publisher, }: { assetAttributes: AssetAttributes publishMetadata?: PublishMetadata @@ -921,6 +951,7 @@ export interface AssetPublishProviderState { password?: string cryptoConfig?: CryptoConfig onEvent?: (next: CreateProgressStep) => void + publisher: Account }) => Promise /** * In Nevermined is possible to register a digital asset that allow users pay for having a @@ -937,6 +968,7 @@ export interface AssetPublishProviderState { * @param nft721.password Password to encrypt metadata * @param nft721.cryptoConfig Setting for encrypting asset * @param nft721.onEvent A callback to handle progress events + * @param nft721.publisher Account of the publisher * @returns The DDO object including the asset metadata and the DID */ publishNFT721: ({ @@ -947,6 +979,7 @@ export interface AssetPublishProviderState { password, cryptoConfig, onEvent, + publisher, }: { nftAttributes: NFTAttributes nftAddress: string @@ -956,6 +989,7 @@ export interface AssetPublishProviderState { password?: string cryptoConfig?: CryptoConfig onEvent?: (next: CreateProgressStep) => void + publisher: Account }) => Promise /** * In Nevermined is possible to register a digital asset that allow users pay for having a @@ -972,6 +1006,7 @@ export interface AssetPublishProviderState { * @param nft1155.password Password to encrypt metadata * @param nft1155.cryptoConfig Setting for encrypting asset * @param nft1155.onEvent A callback to handle progress events + * @param nft1155.publisher Account of the publisher * @returns The DDO object including the asset metadata and the DID */ publishNFT1155: ({ @@ -981,6 +1016,7 @@ export interface AssetPublishProviderState { password, cryptoConfig, onEvent, + publisher, }: { nftAttributes: NFTAttributes publishMetadata?: PublishMetadata @@ -988,6 +1024,7 @@ export interface AssetPublishProviderState { method?: EncryptionMethod password?: string cryptoConfig?: CryptoConfig + publisher: Account onEvent?: (next: CreateProgressStep) => void }) => Promise } diff --git a/catalog/src/utils/marketplace_token.ts b/catalog/src/utils/marketplace_token.ts index 6e165ed..9d6136c 100644 --- a/catalog/src/utils/marketplace_token.ts +++ b/catalog/src/utils/marketplace_token.ts @@ -1,4 +1,4 @@ -import { Nevermined, Logger } from '@nevermined-io/sdk' +import { Nevermined, Logger, Account } from '@nevermined-io/sdk' import jwt, { JwtPayload } from 'jsonwebtoken' import { MarketplaceAPIToken } from '../types' @@ -44,9 +44,8 @@ export const fetchMarketplaceApiTokenFromLocalStorage = (): MarketplaceAPIToken * @param sdk Instance of SDK object * @return Auth token object which generated from Marketplace API */ -export const newMarketplaceApiToken = async (sdk: Nevermined): Promise => { +export const newMarketplaceApiToken = async (sdk: Nevermined, account: Account): Promise => { try { - const [account] = await sdk.accounts.list() const credential = await sdk.utils.jwt.generateClientAssertion(account) const token = await sdk.services.marketplace.login(credential) saveMarketplaceApiTokenToLocalStorage({ token }) diff --git a/catalog/unit-tests/catalog/catalog.access.spec.tsx b/catalog/unit-tests/catalog/catalog.access.spec.tsx index f43df2f..942c029 100644 --- a/catalog/unit-tests/catalog/catalog.access.spec.tsx +++ b/catalog/unit-tests/catalog/catalog.access.spec.tsx @@ -39,7 +39,7 @@ describe('Nevermined subscription', () => { const { result } = renderHook( () => { - const { nfts, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { nfts, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [ agreementIdResult, setAgreementId] = useState('') useEffect(() => { @@ -51,8 +51,10 @@ describe('Nevermined subscription', () => { (async () => { try { + const [account] = await sdk.accounts.list() const result = await nfts.access({ did: ddo.id, + buyer: account, nftHolder: '0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e', nftAmount: BigNumber.from(1), ercType: 721, @@ -113,8 +115,10 @@ describe('Nevermined subscription', () => { (async () => { try { + const [account] = await sdk.accounts.list() const result = await nfts.access({ did: ddo.id, + buyer: account, nftHolder: '0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e', nftAmount: BigNumber.from(1), ercType: 1155, diff --git a/catalog/unit-tests/catalog/catalog.account.spec.tsx b/catalog/unit-tests/catalog/catalog.account.spec.tsx index d833ad2..4de9599 100644 --- a/catalog/unit-tests/catalog/catalog.account.spec.tsx +++ b/catalog/unit-tests/catalog/catalog.account.spec.tsx @@ -126,7 +126,7 @@ describe('Nevermined account', () => { it('should generate new token', async() => { const { result } = renderHook( () => { - const { account, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { account, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [ token, setToken ] = useState('') useEffect(() => { @@ -138,8 +138,8 @@ describe('Nevermined account', () => { (async () => { try { - - const result = await account.generateToken() + const [userAccount] = await sdk.accounts.list() + const result = await account.generateToken(userAccount) setToken(result.token) } catch (error: any) { @@ -534,7 +534,7 @@ describe('Nevermined account', () => { it('should get all the subscriptions published by the address passed', async () =>{ const { result } = renderHook( () => { - const { account, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { account, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [ subscriptions, setSubscriptions ] = useState([]) useEffect(() => { @@ -546,7 +546,8 @@ describe('Nevermined account', () => { (async () => { try { - const result = await account.getPublishedSubscriptions() + const [userAccount] = await sdk.accounts.list() + const result = await account.getPublishedSubscriptions(userAccount) setSubscriptions([...result.results]) } catch (error: any) { @@ -570,7 +571,7 @@ describe('Nevermined account', () => { it('should get all the subscriptions published and services by the address passed', async () =>{ const { result } = renderHook( () => { - const { account, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { account, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [ subscriptions, setSubscriptions ] = useState([]) useEffect(() => { @@ -582,7 +583,8 @@ describe('Nevermined account', () => { (async () => { try { - const result = await account.getPublishedSubscriptionsAndServices() + const [userAccount] = await sdk.accounts.list() + const result = await account.getPublishedSubscriptionsAndServices(userAccount) setSubscriptions([...result]) } catch (error: any) { @@ -609,7 +611,7 @@ describe('Nevermined account', () => { it('should get all the subscriptions purchased by the address passed', async () =>{ const { result } = renderHook( () => { - const { account, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { account, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [ subscriptions, setSubscriptions ] = useState([]) useEffect(() => { @@ -621,7 +623,8 @@ describe('Nevermined account', () => { (async () => { try { - const result = await account.getPurchasedSubscriptions() + const [userAccount] = await sdk.accounts.list() + const result = await account.getPurchasedSubscriptions(userAccount) setSubscriptions([...result.results]) } catch (error: any) { @@ -645,7 +648,7 @@ describe('Nevermined account', () => { it('should get all the subscriptions purchased and services by the address passed', async () =>{ const { result } = renderHook( () => { - const { account, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { account, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [ subscriptions, setSubscriptions ] = useState([]) useEffect(() => { @@ -657,7 +660,8 @@ describe('Nevermined account', () => { (async () => { try { - const result = await account.getPurchasedSubscriptionsAndServices() + const [userAccount] = await sdk.accounts.list() + const result = await account.getPurchasedSubscriptionsAndServices(userAccount) setSubscriptions([...result]) } catch (error: any) { @@ -720,7 +724,7 @@ describe('Nevermined account', () => { it('should get all the subscriptions published and datasets by the address passed', async () =>{ const { result } = renderHook( () => { - const { account, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { account, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [ subscriptions, setSubscriptions ] = useState([]) useEffect(() => { @@ -732,7 +736,8 @@ describe('Nevermined account', () => { (async () => { try { - const result = await account.getPublishedSubscriptionsAndDatasets() + const [userAccount] = await sdk.accounts.list() + const result = await account.getPublishedSubscriptionsAndDatasets(userAccount) setSubscriptions([...result]) } catch (error: any) { @@ -761,7 +766,7 @@ describe('Nevermined account', () => { it('should get all the subscriptions purchased and datasets by the address passed', async () =>{ const { result } = renderHook( () => { - const { account, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { account, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [ subscriptions, setSubscriptions ] = useState([]) useEffect(() => { @@ -773,7 +778,8 @@ describe('Nevermined account', () => { (async () => { try { - const result = await account.getPublishedSubscriptionsAndDatasets() + const [userAccount] = await sdk.accounts.list() + const result = await account.getPublishedSubscriptionsAndDatasets(userAccount) setSubscriptions([...result]) } catch (error: any) { diff --git a/catalog/unit-tests/catalog/catalog.assets.spec.tsx b/catalog/unit-tests/catalog/catalog.assets.spec.tsx index 3a2e3e4..51d6ae5 100644 --- a/catalog/unit-tests/catalog/catalog.assets.spec.tsx +++ b/catalog/unit-tests/catalog/catalog.assets.spec.tsx @@ -124,7 +124,7 @@ describe('Nevermined assets', () => { const { result } = renderHook( () => { - const { assets, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { assets, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [agrId, setAgrId] = useState('') useEffect(() => { @@ -136,7 +136,8 @@ describe('Nevermined assets', () => { (async () => { try { - const result = await assets.orderAsset(ddo.id) + const [userAccount] = await sdk.accounts.list() + const result = await assets.orderAsset(ddo.id, userAccount) setAgrId(result) } catch (error: any) { console.error(error.message) @@ -172,7 +173,7 @@ describe('Nevermined assets', () => { const { result } = renderHook( () => { - const { assets, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { assets, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [errorMessage, setErrorMessage] = useState('') useEffect(() => { @@ -184,7 +185,8 @@ describe('Nevermined assets', () => { (async () => { try { - await assets.orderAsset(ddo.id) + const [userAccount] = await sdk.accounts.list() + await assets.orderAsset(ddo.id, userAccount) } catch (error: any) { setErrorMessage(error.message) } @@ -221,7 +223,7 @@ describe('Nevermined assets', () => { const { result } = renderHook( () => { - const { assets, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { assets, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [agrId, setAgrId] = useState('') useEffect(() => { @@ -233,7 +235,8 @@ describe('Nevermined assets', () => { (async () => { try { - const result = await assets.orderAsset(ddo.id) + const [userAccount] = await sdk.accounts.list() + const result = await assets.orderAsset(ddo.id, userAccount) setAgrId(result) } catch (error: any) { console.error(error.message) @@ -256,7 +259,7 @@ describe('Nevermined assets', () => { it('should get the agreement id if the nft 721 was purchased by the user already', async () => { const { result } = renderHook( () => { - const { assets, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { assets, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [agrId, setAgrId] = useState('') useEffect(() => { @@ -268,7 +271,8 @@ describe('Nevermined assets', () => { (async () => { try { - const result = await assets.orderNFT721(ddo.id, nftTokenAddress) + const [userAccount] = await sdk.accounts.list() + const result = await assets.orderNFT721(ddo.id, userAccount, nftTokenAddress) setAgrId(result) } catch (error: any) { console.error(error.message) @@ -304,7 +308,7 @@ describe('Nevermined assets', () => { const { result } = renderHook( () => { - const { assets, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { assets, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [agrId, setAgrId] = useState('') useEffect(() => { @@ -316,7 +320,8 @@ describe('Nevermined assets', () => { (async () => { try { - const result = await assets.orderNFT721(ddo.id, nftTokenAddress) + const [userAccount] = await sdk.accounts.list() + const result = await assets.orderNFT721(ddo.id, userAccount, nftTokenAddress) setAgrId(result) } catch (error: any) { console.error(error.message) @@ -339,7 +344,7 @@ describe('Nevermined assets', () => { it('should get the agreement id if the nft 1155 was purchased by the user already', async () => { const { result } = renderHook( () => { - const { assets, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { assets, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [agrId, setAgrId] = useState('') useEffect(() => { @@ -351,7 +356,8 @@ describe('Nevermined assets', () => { (async () => { try { - const result = await assets.orderNFT1155(ddo.id, BigNumber.from(1)) + const [consumer] = await sdk.accounts.list() + const result = await assets.orderNFT1155(ddo.id, BigNumber.from(1), consumer) setAgrId(result) } catch (error: any) { console.error(error.message) @@ -387,7 +393,7 @@ describe('Nevermined assets', () => { const { result } = renderHook( () => { - const { assets, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { assets, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [agrId, setAgrId] = useState('') useEffect(() => { @@ -399,7 +405,8 @@ describe('Nevermined assets', () => { (async () => { try { - const result = await assets.orderNFT1155(ddo.id, BigNumber.from(1)) + const [consumer] = await sdk.accounts.list() + const result = await assets.orderNFT1155(ddo.id, BigNumber.from(1), consumer) setAgrId(result) } catch (error: any) { console.error(error.message) @@ -441,7 +448,7 @@ describe('Nevermined assets', () => { const { result } = renderHook( () => { - const { assets, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { assets, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [isDownloaded, setIsDownloaded] = useState(false) useEffect(() => { @@ -453,7 +460,8 @@ describe('Nevermined assets', () => { (async () => { try { - const result = await assets.downloadAsset({did: ddo.id}) + const [consumer] = await sdk.accounts.list() + const result = await assets.downloadAsset({did: ddo.id, consumer}) setIsDownloaded(result) } catch (error: any) { console.error(error.message) @@ -499,7 +507,7 @@ describe('Nevermined assets', () => { const { result } = renderHook( () => { - const { assets, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { assets, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [isDownloaded, setIsDownloaded] = useState(false) useEffect(() => { @@ -511,7 +519,8 @@ describe('Nevermined assets', () => { (async () => { try { - const result = await assets.downloadAsset({ did: ddo.id}) + const [consumer] = await sdk.accounts.list() + const result = await assets.downloadAsset({ did: ddo.id, consumer}) setIsDownloaded(result) } catch (error: any) { console.error(error.message) @@ -537,7 +546,7 @@ describe('Nevermined assets', () => { it('should download the nft', async () => { const { result } = renderHook( () => { - const { assets, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { assets, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [isDownloaded, setIsDownloaded] = useState(false) useEffect(() => { @@ -549,7 +558,8 @@ describe('Nevermined assets', () => { (async () => { try { - const result = await assets.downloadNFT({did: ddo.id}) + const [consumer] = await sdk.accounts.list() + const result = await assets.downloadNFT({did: ddo.id, consumer}) setIsDownloaded(result as boolean) } catch (error: any) { console.error(error.message) @@ -592,7 +602,8 @@ describe('Nevermined assets', () => { (async () => { try { const result = await assets.getCustomErc20Token( - '0xdF1B443A155b07D2b2cAeA2d99715dC84E812EE2' + '0xdF1B443A155b07D2b2cAeA2d99715dC84E812EE2', + walletAddress ) setCustomErc20Token({ ...result }) } catch (error: any) { @@ -662,7 +673,7 @@ describe('Nevermined assets', () => { it('should transfer the ownership to other account', async () => { const { result } = renderHook( () => { - const { assets, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { assets, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [transfered, setTransfered] = useState(false) useEffect(() => { @@ -674,10 +685,12 @@ describe('Nevermined assets', () => { (async () => { try { + const [userAccount] = await sdk.accounts.list() const result = await assets.transfer({ did: ddo.id, amount: 1, - ercType: 1155 + ercType: 1155, + newOwner: userAccount }) setTransfered(result) } catch (error: any) { @@ -720,7 +733,7 @@ describe('Nevermined assets', () => { const { result } = renderHook( () => { - const { assets, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { assets, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [transfered, setTransfered] = useState(false) useEffect(() => { @@ -732,10 +745,12 @@ describe('Nevermined assets', () => { (async () => { try { + const [userAccount] = await sdk.accounts.list() const result = await assets.transfer({ did: ddo.id, amount: 1, - ercType: 1155 + ercType: 1155, + newOwner: userAccount }) setTransfered(result) } catch (error: any) { @@ -767,7 +782,7 @@ describe('Nevermined assets', () => { const { result } = renderHook( () => { - const { assets, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { assets, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [transfered, setTransfered] = useState(false) useEffect(() => { @@ -779,10 +794,12 @@ describe('Nevermined assets', () => { (async () => { try { + const [userAccount] = await sdk.accounts.list() const result = await assets.transfer({ did: ddo.id, amount: 1, ercType: 1155, + newOwner: userAccount }) setTransfered(result) } catch (error: any) { @@ -823,7 +840,7 @@ describe('Nevermined assets', () => { const { result } = renderHook( () => { - const { assets, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { assets, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [transfered, setTransfered] = useState(false) useEffect(() => { @@ -835,10 +852,12 @@ describe('Nevermined assets', () => { (async () => { try { + const [userAccount] = await sdk.accounts.list() const result = await assets.transfer({ did: ddo.id, amount: 1, - ercType: 1155 + ercType: 1155, + newOwner: userAccount }) setTransfered(result) } catch (error: any) { @@ -885,7 +904,7 @@ describe('Nevermined assets', () => { const { result } = renderHook( () => { - const { assets, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { assets, isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const [transfered, setTransfered] = useState(false) useEffect(() => { @@ -897,10 +916,12 @@ describe('Nevermined assets', () => { (async () => { try { + const [userAccount] = await sdk.accounts.list() const result = await assets.transfer({ did: ddo.id, amount: 1, ercType: 1155, + newOwner: userAccount }) setTransfered(result) } catch (error: any) { @@ -964,7 +985,7 @@ describe('Nevermined assets', () => { const { result } = renderHook( () => { - const { assets, isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { assets, isLoadingSDK, updateSDK,sdk } = Catalog.useNevermined() const [transfered, setTransfered] = useState(false) useEffect(() => { @@ -976,10 +997,12 @@ describe('Nevermined assets', () => { (async () => { try { + const [userAccount] = await sdk.accounts.list() const result = await assets.transfer({ did: ddo.id, amount: 1, - ercType: 1155 + ercType: 1155, + newOwner: userAccount }) setTransfered(result) } catch (error: any) { diff --git a/catalog/unit-tests/mockups.ts b/catalog/unit-tests/mockups.ts index 3dffc2a..552407d 100644 --- a/catalog/unit-tests/mockups.ts +++ b/catalog/unit-tests/mockups.ts @@ -2,7 +2,7 @@ import { faker } from '@faker-js/faker' import { MetaData, Profile, State } from '../src' import jwt from 'jsonwebtoken' -const nftContract = '0xdF1B443A155b07D2b2cAeA2d99715dC84E812FF5' +export const nftContract = '0xdF1B443A155b07D2b2cAeA2d99715dC84E812FF5' export const ddo = { '@context': 'https://w3id.org/did/v1', @@ -954,6 +954,9 @@ export const nevermined = { getId: () => walletAddress, }, ], + getAccount: async () => ({ + getId: () => walletAddress, + }), }, services: { metadata: { diff --git a/catalog/unit-tests/services/services.assets.spec.tsx b/catalog/unit-tests/services/services.assets.spec.tsx index 3241baf..6000def 100644 --- a/catalog/unit-tests/services/services.assets.spec.tsx +++ b/catalog/unit-tests/services/services.assets.spec.tsx @@ -3,7 +3,7 @@ import { renderHook, waitFor } from '@testing-library/react' import { generateTestingUtils } from 'eth-testing' import { appConfig } from '../config' import { Catalog, AssetService, AssetAttributes, NFTAttributes, DDO, RoyaltyKind, getRoyaltyScheme, MarketplaceAPIToken, Nevermined, BigNumber } from '../../src' -import { ddo as assetObject, metadata, walletAddress } from '../mockups' +import { ddo as assetObject, metadata, nftContract, walletAddress } from '../mockups' import { faker } from '@faker-js/faker' import jwt from 'jsonwebtoken' @@ -104,7 +104,7 @@ describe('Assets Service', () => { it('should publish an asset', async() => { const { result } = renderHook( () => { - const { isLoadingSDK, updateSDK, account } = Catalog.useNevermined() + const { isLoadingSDK, updateSDK, account, sdk } = Catalog.useNevermined() const { publishAsset, isPublished } = AssetService.useAssetPublish() const [ddo, setDDO ] = useState({} as DDO) @@ -118,8 +118,10 @@ describe('Assets Service', () => { } (async () => { + const [publisher] = await sdk.accounts.list() const result = await publishAsset({ assetAttributes, + publisher, }) as DDO setDDO(result) @@ -160,8 +162,11 @@ describe('Assets Service', () => { (async () => { nftAttributes.royaltyAttributes = royaltyAttributes(sdk) + const [publisher] = await sdk.accounts.list() const result = await publishNFT721({ - nftAttributes + nftAttributes, + nftAddress: nftContract, + publisher, }) as DDO setDDO(result) @@ -189,7 +194,7 @@ describe('Assets Service', () => { it('should publish an nft1155', async() => { const { result } = renderHook( () => { - const { isLoadingSDK, updateSDK } = Catalog.useNevermined() + const { isLoadingSDK, updateSDK, sdk } = Catalog.useNevermined() const { publishNFT1155, isPublished } = AssetService.useAssetPublish() const [ddo, setDDO ] = useState({} as DDO) @@ -201,8 +206,10 @@ describe('Assets Service', () => { } (async () => { + const [publisher] = await sdk.accounts.list() const result = await publishNFT1155({ - nftAttributes + nftAttributes, + publisher, }) as DDO setDDO(result) @@ -250,7 +257,7 @@ describe('Assets Service', () => { description: '', type: 'dataset', category: 'None', - price: 0, + price: '0', assetFiles: [] }) @@ -293,7 +300,7 @@ describe('Assets Service', () => { description: faker.lorem.sentence(), type: 'dataset', category: 'None', - price: 0, + price: '0', assetFiles: [] }) @@ -303,7 +310,7 @@ describe('Assets Service', () => { description: '', type: 'dataset', category: 'None', - price: 0, + price: '0', assetFiles: [] }) @@ -326,7 +333,7 @@ describe('Assets Service', () => { description: '', type: 'dataset', category: 'None', - price: 0, + price: '0', assetFiles: [] }) }) @@ -337,7 +344,7 @@ describe('Assets Service', () => { renderHook( () => { - const { isLoadingSDK, updateSDK, account } = Catalog.useNevermined() + const { isLoadingSDK, updateSDK, account, sdk } = Catalog.useNevermined() const { publishAsset, errorAssetMessage } = AssetService.useAssetPublish() jest.spyOn(account, 'isTokenValid').mockReturnValue(false) @@ -364,8 +371,10 @@ describe('Assets Service', () => { } (async () => { + const [publisher] = await sdk.accounts.list() await publishAsset({ assetAttributes, + publisher, }) as DDO })() }, [isLoadingSDK, errorAssetMessage]) diff --git a/providers/package.json b/providers/package.json index 556045b..8c9bfc9 100644 --- a/providers/package.json +++ b/providers/package.json @@ -1,7 +1,7 @@ { "name": "@nevermined-io/providers", "private": false, - "version": "1.6.6", + "version": "1.7.0", "main": "./dist/index.js", "types": "./dist/index.d.ts", "dependencies": {