From 1547aece28bf5d9e9f022b0f759f953603d84d10 Mon Sep 17 00:00:00 2001 From: Ivaylo Nikolov Date: Mon, 29 Jul 2024 10:10:34 +0300 Subject: [PATCH] chore: lint change Signed-off-by: Ivaylo Nikolov --- package.json | 2 +- src/token/TokenRejectFlow.js | 46 +++++++++++-------- src/token/TokenRejectTransaction.js | 5 +- .../TokenRejectFlowIntegrationTest.js | 1 - .../integration/TokenRejectIntegrationTest.js | 4 +- test/unit/TokenRejectFlow.js | 2 - test/unit/TokenRejectTransaction.js | 14 ------ 7 files changed, 32 insertions(+), 42 deletions(-) diff --git a/package.json b/package.json index 49fb18a83..be2958762 100644 --- a/package.json +++ b/package.json @@ -130,4 +130,4 @@ "optional": true } } -} \ No newline at end of file +} diff --git a/src/token/TokenRejectFlow.js b/src/token/TokenRejectFlow.js index d0d89f7d8..9f011ef8d 100644 --- a/src/token/TokenRejectFlow.js +++ b/src/token/TokenRejectFlow.js @@ -18,8 +18,6 @@ * ‍ */ import AccountId from "../account/AccountId.js"; -import NftId from "../token/NftId.js"; -import TokenId from "../token/TokenId.js"; import TokenRejectTransaction from "../token/TokenRejectTransaction.js"; import TokenDissociateTransaction from "../token/TokenDissociateTransaction.js"; @@ -39,10 +37,12 @@ import TokenDissociateTransaction from "../token/TokenDissociateTransaction.js"; * @typedef {import("../PrivateKey.js").default} PrivateKey * @typedef {import("../channel/Channel.js").default} Channel * @typedef {import("../client/Client.js").default<*, *>} Client - * @typedef {import("../Signer.js").Signer} Signer + * @typedef {import("../Signer.js").default} Signer * @typedef {import("../transaction/TransactionId.js").default} TransactionId * @typedef {import("../transaction/Transaction.js").default} Transaction * @typedef {import("../transaction/TransactionResponse.js").default} TransactionResponse + * @typedef {import("../token/TokenId.js").default} TokenId + * @typedef {import("../token/NftId.js").default} NftId * */ @@ -54,7 +54,7 @@ export default class TokenRejectFlow { /** * @private * @type {AccountId | string | null} - * */ + */ this._ownerId = null; /** @@ -66,7 +66,7 @@ export default class TokenRejectFlow { /** * @private * @type {NftId[]} - * */ + */ this._nftIds = []; /** @@ -89,7 +89,7 @@ export default class TokenRejectFlow { /** * @private - * @type {*}} + * @type {((message: Uint8Array) => Promise) | null} */ this._transactionSigner = null; } @@ -190,7 +190,7 @@ export default class TokenRejectFlow { /** * * @param {import("../SignerSignature.js").PublicKey} publicKey - * @param {import("../Signer.js").Signer} signer + * @param {((message: Uint8Array) => Promise)} signer * @returns {this} */ signWith(publicKey, signer) { @@ -202,6 +202,7 @@ export default class TokenRejectFlow { /** * @param {Client} client + * @returns {this} */ signWithOperator(client) { const operator = client.getOperator(); @@ -223,15 +224,18 @@ export default class TokenRejectFlow { transaction.freezeWith(this._freezeWithClient); } if (this._signPrivateKey) { - transaction.sign(this._signPrivateKey); + void transaction.sign(this._signPrivateKey); } else if (this._signPublicKey && this._transactionSigner) { - transaction.signWith(this._signPublicKey, this._transactionSigner); + void transaction.signWith( + this._signPublicKey, + this._transactionSigner, + ); } } /** * * @param {Client} client - * @returns + * @returns {this} */ freezeWith(client) { this._freezeWithClient = client; @@ -243,7 +247,7 @@ export default class TokenRejectFlow { * @returns {Promise} */ async execute(client) { - const tokenRejectTxn = await new TokenRejectTransaction() + const tokenRejectTxn = new TokenRejectTransaction() .setTokenIds(this.tokenIds) .setNftIds(this.nftIds); @@ -253,15 +257,17 @@ export default class TokenRejectFlow { this.fillOutTransaction(tokenRejectTxn); - // get token id of nft and remove duplicates - const nftTokenIds = [ - ...new Set(this.nftIds.map((nftId) => nftId.tokenId)), - ]; - const tokenDissociateTxn = - await new TokenDissociateTransaction().setTokenIds([ - ...this.tokenIds, - ...nftTokenIds, - ]); + /* Get all token ids from NFT and remove duplicates as duplicated IDs + will trigger a TOKEN_REFERENCE_REPEATED error. */ + const nftTokenIds = this.nftIds + .map((nftId) => nftId.tokenId) + .filter(function (value, index, array) { + return array.indexOf(value) === index; + }); + + const tokenDissociateTxn = new TokenDissociateTransaction().setTokenIds( + [...this.tokenIds, ...nftTokenIds], + ); if (this.ownerId != null) { tokenDissociateTxn.setAccountId(this.ownerId); diff --git a/src/token/TokenRejectTransaction.js b/src/token/TokenRejectTransaction.js index dbf0f8b2c..6c75980e7 100644 --- a/src/token/TokenRejectTransaction.js +++ b/src/token/TokenRejectTransaction.js @@ -170,7 +170,7 @@ export default class TokenRejectTransaction extends Transaction { /** * * @param {NftId[] | string[]} nftIds - * @returns + * @returns {this} */ setNftIds(nftIds) { this._requireNotFrozen(); @@ -194,7 +194,7 @@ export default class TokenRejectTransaction extends Transaction { } /** - * @returns {?AccountId} } + * @returns {?AccountId} */ get ownerId() { return this._owner; @@ -202,6 +202,7 @@ export default class TokenRejectTransaction extends Transaction { /** * @param {AccountId | string} owner + * @returns {this} */ setOwnerId(owner) { this._requireNotFrozen(); diff --git a/test/integration/TokenRejectFlowIntegrationTest.js b/test/integration/TokenRejectFlowIntegrationTest.js index c0ad7ee63..83ab17586 100644 --- a/test/integration/TokenRejectFlowIntegrationTest.js +++ b/test/integration/TokenRejectFlowIntegrationTest.js @@ -6,7 +6,6 @@ import { PrivateKey, TokenAssociateTransaction, TokenCreateTransaction, - TokenDissociateTransaction, TokenMintTransaction, TokenRejectFlow, TokenType, diff --git a/test/integration/TokenRejectIntegrationTest.js b/test/integration/TokenRejectIntegrationTest.js index c3d623821..cbe4c1155 100644 --- a/test/integration/TokenRejectIntegrationTest.js +++ b/test/integration/TokenRejectIntegrationTest.js @@ -215,7 +215,7 @@ describe("TokenRejectIntegrationTest", function () { } }); - describe("should revert", async function () { + describe("should revert", function () { it("when paused FT", async function () { this.timeout(120000); @@ -553,7 +553,7 @@ describe("TokenRejectIntegrationTest", function () { } }); - describe("should revert", async function () { + describe("should revert", function () { it("when paused NFT", async function () { this.timeout(120000); diff --git a/test/unit/TokenRejectFlow.js b/test/unit/TokenRejectFlow.js index a71e5f960..33c10ab4d 100644 --- a/test/unit/TokenRejectFlow.js +++ b/test/unit/TokenRejectFlow.js @@ -21,8 +21,6 @@ describe("TokenRejectFlow", function () { new NftId(tokenIds[2], 3), ]; - const validStart = 1554158542; - let tx; it("should set owner id", function () { diff --git a/test/unit/TokenRejectTransaction.js b/test/unit/TokenRejectTransaction.js index d9d686083..9120aa002 100644 --- a/test/unit/TokenRejectTransaction.js +++ b/test/unit/TokenRejectTransaction.js @@ -68,20 +68,6 @@ describe("Transaction", function () { ); }); - it("should revert when updating token ids when frozen", function () { - const tokenIds = [new TokenId(1), new TokenId(2)]; - const owner = new AccountId(1); - const timestamp = new Timestamp(14, 15); - - const tx = new TokenRejectTransaction() - .setNodeAccountIds([new AccountId(10, 11, 12)]) - .setTransactionId(TransactionId.withValidStart(owner, timestamp)) - .freeze(); - expect(() => tx.setTokenIds(tokenIds)).to.throw( - "transaction is immutable; it has at least one signature or has been explicitly frozen", - ); - }); - it("should set nft ids", function () { const nftIds = [new NftId(1), new NftId(2)]; const tx = new TokenRejectTransaction().setNftIds(nftIds);