Skip to content

Commit

Permalink
chore lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsmithies committed Nov 17, 2022
1 parent 2a38d3f commit 5b67416
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
4 changes: 3 additions & 1 deletion app/handler/batchTransferNftHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ async function BatchTransferNftHandler(req, res) {
}

const { hashgraphClient } = req.context
const sendResponse = await hashgraphClient.batchTransferNft(batchTransferPayload)
const sendResponse = await hashgraphClient.batchTransferNft(
batchTransferPayload
)

if (sendResponse.error) {
return Response.unprocessibleEntity(res, sendResponse.error)
Expand Down
14 changes: 6 additions & 8 deletions app/hashgraph/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,12 +694,7 @@ class HashgraphClient extends HashgraphClientContract {
* @param ser
* @returns {Promise<void>}
*/
multipleNftTransfer = async ({
token_id,
receiver_id,
serials
}) => {

multipleNftTransfer = async ({ token_id, receiver_id, serials }) => {
const client = this.#client

const transfer = await new TransferTransaction()
Expand Down Expand Up @@ -755,7 +750,11 @@ class HashgraphClient extends HashgraphClientContract {

// Required recur fn needed for pagination
const sendNftTransaction = async (limit, paginationLink) => {
const nfts = await Mirror.fetchNftIdsForBatchTransfer(token_id, limit, paginationLink)
const nfts = await Mirror.fetchNftIdsForBatchTransfer(
token_id,
limit,
paginationLink
)

const transfer = await this.multipleNftTransfer({
token_id,
Expand All @@ -770,7 +769,6 @@ class HashgraphClient extends HashgraphClientContract {
}

const cycleBatchTransfers = async (cycle, results = [], paginationLink) => {

if (!cycle.length) {
return results
}
Expand Down
9 changes: 5 additions & 4 deletions app/utils/batchable.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

const BATCH_LIMITS = {
nftTransfers: 10
}
Expand All @@ -10,15 +9,17 @@ const BATCH_LIMITS = {
* @returns {any[]}
*/
function nftTransfer(amount) {

// mod rem diff
const rem = amount % BATCH_LIMITS.nftTransfers

// Basal cycle for batch, as a whole number
const max = (amount - rem) / BATCH_LIMITS.nftTransfers

// When rem is falsely, remove -- more simple then if
const cycle = Array(max).fill(BATCH_LIMITS.nftTransfers).concat(rem).filter(e => e)
// When rem is falsely, remove -- more simple then if
const cycle = Array(max)
.fill(BATCH_LIMITS.nftTransfers)
.concat(rem)
.filter(e => e)

// For readability
return cycle
Expand Down
18 changes: 7 additions & 11 deletions app/utils/mirrornode.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ const queryNftAccountOwner = (token_id, serial) =>
`${mirrornode}/api/v1/tokens/${token_id}/nfts/${serial}`
const queryNftForOwner = (token_id, account_id) =>
`${mirrornode}/api/v1/tokens/${token_id}/nfts/?account.id=${account_id}`
const queryTreasuryTokenBalance = (token_id, account_id) => `${mirrornode}/api/v1/tokens/${token_id}/balances/?account.id=${account_id}`
const getNftByLimit = (token_id, account_id, limit = 20) => `${mirrornode}/api/v1/tokens/${token_id}/nfts?account.id=${account_id}&order=asc&limit=${limit}`
const queryReq = (next) => `${mirrornode}${next}`
const queryTreasuryTokenBalance = (token_id, account_id) =>
`${mirrornode}/api/v1/tokens/${token_id}/balances/?account.id=${account_id}`
const getNftByLimit = (token_id, account_id, limit = 20) =>
`${mirrornode}/api/v1/tokens/${token_id}/nfts?account.id=${account_id}&order=asc&limit=${limit}`
const queryReq = next => `${mirrornode}${next}`

const MIRRORNODE_WAIT_MS = 500
const MIRRORNODE_TRIES = 5
Expand Down Expand Up @@ -99,9 +101,7 @@ async function checkTreasuryHasNftAmount(
queryTreasuryTokenBalance(nft_id, expected)
)

const {
balances
} = result.data
const { balances } = result.data

if (!balances.length) {
return false
Expand All @@ -110,7 +110,6 @@ async function checkTreasuryHasNftAmount(
return balances[0].balance >= amount
}


/**
* Fetch the nft ids for a particular NFT tx, include the "next" id
*
Expand All @@ -130,10 +129,7 @@ async function fetchNftIdsForBatchTransfer(
link ? queryReq(link) : getNftByLimit(nft_id, expected, limit)
)

const {
nfts,
links
} = result.data
const { nfts, links } = result.data

const serials = nfts.splice(0, limit)

Expand Down

0 comments on commit 5b67416

Please sign in to comment.