@@ -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 } ;
0 commit comments