Skip to content
This repository was archived by the owner on Oct 19, 2023. It is now read-only.

Commit f6672d1

Browse files
Merge pull request #143 from nevermined-io/issue/return_agreementID
Issue/return agreement
2 parents d17a1f9 + 1998791 commit f6672d1

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

lib/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nevermined-io/catalog-core",
3-
"version": "0.0.25",
3+
"version": "0.0.26",
44
"private": false,
55
"scripts": {
66
"watch": "./node_modules/.bin/nodemon",
@@ -36,7 +36,7 @@
3636
"react": "*"
3737
},
3838
"dependencies": {
39-
"@nevermined-io/nevermined-sdk-js": "^0.22.5",
39+
"@nevermined-io/nevermined-sdk-js": "^0.23.1",
4040
"@types/jsonwebtoken": "^8.5.8",
4141
"axios": "^0.27.2",
4242
"axios-retry": "^3.3.1",

lib/src/nevermined.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -895,31 +895,44 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv
895895
* }
896896
* ```
897897
*/
898+
899+
898900
const subscription = {
901+
902+
899903
/**
900904
* Order a NFT asset and transfer and delegate it to the subscription buyer
901905
* @param subscriptionDid Id of the NFT to subscribe
902906
* @param buyer The account who buy the subscription of the NFT asset
903907
* @param nftHolder The owner of the NFT asset
904908
* @param nftAmount The amount of NFT asset to buy
905909
* @param nftType NFT asset type which can be 721 or 1155
906-
* @returns It is true if the subscription was successfully completed
910+
* @returns string that contains the id of the agreement
911+
* @throws Error when there is an exception ordering the nft or the transferForDelegate method returns false
907912
*/
908-
buySubscription: async (subscriptionDid: string, buyer: Account, nftHolder: string, nftAmount: number, nftType: NftTypes): Promise<boolean> => {
913+
buySubscription: async (subscriptionDid: string, buyer: Account, nftHolder: string, nftAmount: number, nftType: NftTypes): Promise<string> => {
914+
915+
let agreementId = ''
916+
let transferResult = false
909917
try {
910-
const agreementId = nftType === 721 ? await sdk.nfts.order721(subscriptionDid, buyer): await sdk.nfts.order(subscriptionDid, nftAmount, buyer);
911-
return sdk.nfts.transferForDelegate(
918+
agreementId = nftType === 721 ? await sdk.nfts.order721(subscriptionDid, buyer): await sdk.nfts.order(subscriptionDid, nftAmount, buyer);
919+
transferResult = await sdk.nfts.transferForDelegate(
912920
agreementId,
913921
nftHolder,
914922
buyer.getId(),
915923
nftAmount,
916924
nftType
917925
)
918-
919926
} catch (error) {
920927
verbose && Logger.error(error);
921-
return false;
928+
throw error
922929
}
930+
931+
if (!transferResult)
932+
throw new Error("Error delegating the NFT of the subscription with agreement " + agreementId)
933+
934+
return agreementId
935+
923936
},
924937

925938
};

lib/src/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ export interface Transfer {
223223
}
224224

225225
export interface SubscriptionActions {
226-
buySubscription: (subscriptionDid: string, buyer: Account, nftHolder: string, nftAmount: number, nftType: NftTypes) => Promise<boolean>;
226+
buySubscription: (subscriptionDid: string, buyer: Account, nftHolder: string, nftAmount: number, nftType: NftTypes) => Promise<string>;
227227
}
228228

229229
export type { NftTypes } from '@nevermined-io/nevermined-sdk-js/dist/node/gateway/Gateway';

0 commit comments

Comments
 (0)