Skip to content

Commit

Permalink
chore: lint change
Browse files Browse the repository at this point in the history
Signed-off-by: Ivaylo Nikolov <[email protected]>
  • Loading branch information
ivaylonikolov7 committed Jul 29, 2024
1 parent dbfc39a commit 9f27526
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@
"optional": true
}
}
}
}
46 changes: 26 additions & 20 deletions src/token/TokenRejectFlow.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
* ‍
*/
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";

/**
* @typedef {import("../PrivateKey.js").default} PrivateKey
* @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
*
*/

Expand All @@ -41,7 +41,7 @@ export default class TokenRejectFlow {
/**
* @private
* @type {AccountId | string | null}
* */
*/
this._ownerId = null;

/**
Expand All @@ -53,7 +53,7 @@ export default class TokenRejectFlow {
/**
* @private
* @type {NftId[]}
* */
*/
this._nftIds = [];

/**
Expand All @@ -76,7 +76,7 @@ export default class TokenRejectFlow {

/**
* @private
* @type {*}}
* @type {((message: Uint8Array) => Promise<Uint8Array>) | null}
*/
this._transactionSigner = null;
}
Expand Down Expand Up @@ -177,7 +177,7 @@ export default class TokenRejectFlow {
/**
*
* @param {import("../SignerSignature.js").PublicKey} publicKey
* @param {import("../Signer.js").Signer} signer
* @param {((message: Uint8Array) => Promise<Uint8Array>)} signer
* @returns {this}
*/
signWith(publicKey, signer) {
Expand All @@ -189,6 +189,7 @@ export default class TokenRejectFlow {

/**
* @param {Client} client
* @returns {this}
*/
signWithOperator(client) {
const operator = client.getOperator();
Expand All @@ -210,15 +211,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;
Expand All @@ -230,7 +234,7 @@ export default class TokenRejectFlow {
* @returns {Promise<TransactionResponse>}
*/
async execute(client) {
const tokenRejectTxn = await new TokenRejectTransaction()
const tokenRejectTxn = new TokenRejectTransaction()
.setTokenIds(this.tokenIds)
.setNftIds(this.nftIds);

Expand All @@ -240,15 +244,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);
Expand Down
5 changes: 3 additions & 2 deletions src/token/TokenRejectTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export default class TokenRejectTransaction extends Transaction {
/**
*
* @param {NftId[] | string[]} nftIds
* @returns
* @returns {this}
*/
setNftIds(nftIds) {
this._requireNotFrozen();
Expand All @@ -215,14 +215,15 @@ export default class TokenRejectTransaction extends Transaction {
}

/**
* @returns {?AccountId} }
* @returns {?AccountId}
*/
get ownerId() {
return this._owner;
}

/**
* @param {AccountId | string} owner
* @returns {this}
*/
setOwnerId(owner) {
this._requireNotFrozen();
Expand Down
1 change: 0 additions & 1 deletion test/integration/TokenRejectFlowIntegrationTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
PrivateKey,
TokenAssociateTransaction,
TokenCreateTransaction,
TokenDissociateTransaction,
TokenMintTransaction,
TokenRejectFlow,
TokenType,
Expand Down
2 changes: 0 additions & 2 deletions test/unit/TokenRejectFlow.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ describe("TokenRejectFlow", function () {
new NftId(tokenIds[2], 3),
];

const validStart = 1554158542;

let tx;

it("should set owner id", function () {
Expand Down
14 changes: 0 additions & 14 deletions test/unit/TokenRejectTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,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);
Expand Down

0 comments on commit 9f27526

Please sign in to comment.