diff --git a/app/handler/claimNftHandler.js b/app/handler/claimNftHandler.js index 9f71682..1d4e2ae 100644 --- a/app/handler/claimNftHandler.js +++ b/app/handler/claimNftHandler.js @@ -21,12 +21,16 @@ async function ClaimNftHandler(req, res) { const claimablePayload = await claimableTokenCheck(claimPayload) if (claimablePayload.error) { - return Response.unprocessibleEntity(res, claimablePayload.error) + return Response.unprocessibleEntity(res, [claimablePayload.error]) } const { hashgraphClient } = req.context const sendResponse = await hashgraphClient.transferNft(claimPayload) + if (sendResponse.error) { + return Response.unprocessibleEntity(res, sendResponse.error) + } + if (sendResponse) { return Response.json(res, sendResponse) } diff --git a/app/handler/mintNftHandler.js b/app/handler/mintNftHandler.js index fb03a25..c679372 100644 --- a/app/handler/mintNftHandler.js +++ b/app/handler/mintNftHandler.js @@ -19,6 +19,10 @@ async function MintNftHandler(req, res) { cid }) + if (token.errors) { + return Response.unprocessibleEntity(res, token.errors) + } + Response.json(res, token) } diff --git a/app/handler/transferNftHandler.js b/app/handler/transferNftHandler.js index 2ea1f8c..099568c 100644 --- a/app/handler/transferNftHandler.js +++ b/app/handler/transferNftHandler.js @@ -20,7 +20,7 @@ async function TransferNftHandler(req, res) { const sendResponse = await hashgraphClient.transferNft(transferPayload) if (sendResponse.error) { - return Response.unprocessibleEntity(res, sendResponse) + return Response.unprocessibleEntity(res, sendResponse.error) } if (sendResponse) { diff --git a/app/hashgraph/client.js b/app/hashgraph/client.js index 5f7c5ad..0d4180a 100644 --- a/app/hashgraph/client.js +++ b/app/hashgraph/client.js @@ -242,6 +242,7 @@ class HashgraphClient extends HashgraphClientContract { const client = this.#client const transaction = new AccountCreateTransaction() .setKey(publicKey) + .setMaxAutomaticTokenAssociations(10) .setInitialBalance(0.1) const txResponse = await transaction.execute(client) @@ -564,13 +565,22 @@ class HashgraphClient extends HashgraphClientContract { // TODO: If there are issues in the future we may need to await the receipt to check. const txResponse = await signedTx.execute(client) - const receipt = await txResponse.getReceipt(client) - const minted_serial_numbers = receipt.serials.map(serial => serial.low) - return { - token_id, - amount, - minted_serial_numbers + try { + const receipt = await txResponse.getReceipt(client) + const minted_serial_numbers = receipt.serials.map(serial => serial.low) + + return { + token_id, + amount, + minted_serial_numbers + } + } catch (e) { + return { + errors: [ + "Something went wrong, likely that the token id probably incorrect" + ] + } } } @@ -597,7 +607,9 @@ class HashgraphClient extends HashgraphClientContract { if (!hasNft) { return { - error: `The treasury does not hold the token ${token_id} of serial ${serial_number}` + error: [ + `The treasury does not hold the token ${token_id} of serial ${serial_number}` + ] } } @@ -622,8 +634,9 @@ class HashgraphClient extends HashgraphClientContract { } catch (e) { return { token_id, - error: + error: [ "Transfer failed, ensure that the recipient account is valid and has associated to the token" + ] } } } diff --git a/app/utils/mirrornode.js b/app/utils/mirrornode.js index 4735970..d215c69 100644 --- a/app/utils/mirrornode.js +++ b/app/utils/mirrornode.js @@ -29,14 +29,17 @@ const retryableMirrorQuery = async ( } catch (e) { if (e.response.status === Status.NOT_FOUND) { return { - error: + error: [ "Expected resource was not found, did you include a parameter like an NFT ID that isn't on ledger?" + ] } } if (attempts > tries) { return { - error: `Hedera Mirrornode Overloaded after ${tries} attempts, unable to process query` + error: [ + `Hedera Mirrornode Overloaded after ${tries} attempts, unable to process query` + ] } }