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

Commit 1998791

Browse files
committed
fix buySubscription
1 parent dfea6a9 commit 1998791

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

lib/src/nevermined.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -913,28 +913,26 @@ export const NeverminedProvider = ({ children, config, verbose }: NeverminedProv
913913
buySubscription: async (subscriptionDid: string, buyer: Account, nftHolder: string, nftAmount: number, nftType: NftTypes): Promise<string> => {
914914

915915
let agreementId = ''
916+
let transferResult = false
916917
try {
917918
agreementId = nftType === 721 ? await sdk.nfts.order721(subscriptionDid, buyer): await sdk.nfts.order(subscriptionDid, nftAmount, buyer);
918-
sdk.nfts.transferForDelegate(
919+
transferResult = await sdk.nfts.transferForDelegate(
919920
agreementId,
920921
nftHolder,
921922
buyer.getId(),
922923
nftAmount,
923924
nftType
924-
).then((result: boolean) => {
925-
if (!result)
926-
throw new Error("Error delegating the NFT of the subscription with agreement " + agreementId)
927-
}
928925
)
929-
return agreementId
930926
} catch (error) {
931927
verbose && Logger.error(error);
932-
let errorMessage = "Error buying the subscription: "
933-
if (error instanceof Error) {
934-
errorMessage = errorMessage.concat(errorMessage)
935-
}
936-
throw new Error (errorMessage)
928+
throw error
937929
}
930+
931+
if (!transferResult)
932+
throw new Error("Error delegating the NFT of the subscription with agreement " + agreementId)
933+
934+
return agreementId
935+
938936
},
939937

940938
};

0 commit comments

Comments
 (0)