From 9f4faba43793ce706c858a68c044b759ca6ecde5 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 12 Jan 2024 11:56:21 +0200 Subject: [PATCH] Refactor after review --- src/services/txHistory/index.ts | 8 ++++---- src/services/txHistory/queue.ts | 10 +++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/services/txHistory/index.ts b/src/services/txHistory/index.ts index d29462b..1cbf3c7 100644 --- a/src/services/txHistory/index.ts +++ b/src/services/txHistory/index.ts @@ -1,6 +1,6 @@ import { gql } from 'graphql-request' import { u8aToHex } from '@polkadot/util' -import { decodeAddress } from '@polkadot/util-crypto' +import { decodeAddress, isEthereumAddress } from '@polkadot/util-crypto' import { getOrCreateQueue } from './queue' import { txAggregatorGraphQlClient } from '../../constant/graphQlClients' @@ -88,16 +88,16 @@ export const getAccountTxHistoryWithQueue = async (props: GetAccountTransactions const jobState = await jobByAddress.getState() if (jobState === 'completed') { - await jobByAddress.remove() + jobByAddress.remove() actualData = true } } else { const taskPayload = { - publicKey: u8aToHex(decodeAddress(address)) + publicKey: isEthereumAddress(address) ? address : u8aToHex(decodeAddress(address)) } - await queue.add(ADD_QUEUE_JOB_NAME, taskPayload, { + queue.add(ADD_QUEUE_JOB_NAME, taskPayload, { attempts: 5, jobId, removeOnComplete: false, diff --git a/src/services/txHistory/queue.ts b/src/services/txHistory/queue.ts index 3b0af34..da1c17b 100644 --- a/src/services/txHistory/queue.ts +++ b/src/services/txHistory/queue.ts @@ -4,10 +4,14 @@ let queue = null export const getOrCreateQueue = () => { if (!queue) { + const host = process.env.AGGREGATOR_REDIS_HOST + const password = process.env.AGGREGATOR_REDIS_PASSWORD + const port = process.env.AGGREGATOR_REDIS_PORT as unknown as number + const aggregatorRedisConfig = { - host: process.env.AGGREGATOR_REDIS_HOST || '', - password: process.env.AGGREGATOR_REDIS_PASSWORD || '', - port: (process.env.AGGREGATOR_REDIS_PORT as unknown as number) || 0 + host, + password, + port } queue = new Queue('ACCOUNT_AGGREGATION_FLOW', {