diff --git a/server/lib/rippled.js b/server/lib/rippled.js index 7e90d8c27..7d1c27467 100644 --- a/server/lib/rippled.js +++ b/server/lib/rippled.js @@ -4,12 +4,14 @@ const utils = require('./utils') const streams = require('./streams') const RIPPLEDS = [] -process.env.VITE_RIPPLED_HOST?.split(',').forEach((d) => { - const rippled = d.split(':') - RIPPLEDS.push( - `wss://${rippled[0]}:${rippled[1] || process.env.VITE_RIPPLED_WS_PORT}`, - `wss://${rippled[0]}`, - ) +process.env.VITE_RIPPLED_HOST?.split(',').forEach((host) => { + if (host?.includes(':')) { + RIPPLEDS.push(`wss://${host}`) + } else if (process.env.VITE_RIPPLED_WS_PORT) { + RIPPLEDS.push(`wss://${host}:${process.env.VITE_RIPPLED_WS_PORT}`) + } else { + RIPPLEDS.push(`wss://${host}`) + } }) const RIPPLED_CLIENT = new XrplClient(RIPPLEDS, { tryAllNodes: true }) diff --git a/server/routes/v1/tokens.js b/server/routes/v1/tokens.js index 072dcf5ab..0fcadbe09 100644 --- a/server/routes/v1/tokens.js +++ b/server/routes/v1/tokens.js @@ -41,12 +41,15 @@ async function fetchXRPLMetaTokens(offset) { }, ) .then((resp) => resp.data) - .catch((e) => log.error(e)) + .catch((e) => { + log.error(e) + return { count: 0 } + }) } async function cacheXRPLMetaTokens() { let offset = 0 - let tokensDataBatch = [] + let tokensDataBatch = {} const allTokensFetched = [] tokensDataBatch = await fetchXRPLMetaTokens(0) diff --git a/src/containers/shared/SocketContext.tsx b/src/containers/shared/SocketContext.tsx index a8ed6f217..17ef964e4 100644 --- a/src/containers/shared/SocketContext.tsx +++ b/src/containers/shared/SocketContext.tsx @@ -29,11 +29,13 @@ function getSocket(rippledUrl?: string): ExplorerXrplClient { if (host?.includes(':')) { wsUrls.push(`${prefix}://${host}`) + } else if (process.env.VITE_RIPPLED_WS_PORT) { + wsUrls.push(`${prefix}://${host}:${process.env.VITE_RIPPLED_WS_PORT}`) + if (process.env.VITE_ENVIRONMENT === 'custom') { + wsUrls.push(`${prefix}://${host}`) + } } else { - wsUrls.push.apply(wsUrls, [ - `${prefix}://${host}:${process.env.VITE_RIPPLED_WS_PORT}`, - `${prefix}://${host}:443`, - ]) + wsUrls.push(`${prefix}://${host}`) } }) diff --git a/src/containers/shared/test/SocketContext.test.ts b/src/containers/shared/test/SocketContext.test.ts index 2c268ed56..2a67fae26 100644 --- a/src/containers/shared/test/SocketContext.test.ts +++ b/src/containers/shared/test/SocketContext.test.ts @@ -28,7 +28,7 @@ describe('getSocket', () => { const client = getSocket() expect(XrplClient).toHaveBeenNthCalledWith( 1, - ['wss://somewhere.com:51233', 'wss://somewhere.com:443'], + ['wss://somewhere.com:51233'], { tryAllNodes: true, }, @@ -47,12 +47,7 @@ describe('getSocket', () => { const client = getSocket() expect(XrplClient).toHaveBeenNthCalledWith( 1, - [ - 'wss://somewhere.com:51233', - 'wss://somewhere.com:443', - 'wss://elsewhere.com:51233', - 'wss://elsewhere.com:443', - ], + ['wss://somewhere.com:51233', 'wss://elsewhere.com:51233'], { tryAllNodes: true, }, @@ -71,7 +66,7 @@ describe('getSocket', () => { const client = getSocket() expect(XrplClient).toHaveBeenNthCalledWith( 1, - ['ws://somewhere.com:51233', 'ws://somewhere.com:443'], + ['ws://somewhere.com:51233'], { tryAllNodes: true, }, @@ -120,13 +115,9 @@ describe('getSocket', () => { it('should use ws when supplied entry is for a localhost', () => { const client = getSocket('localhost') - expect(XrplClient).toHaveBeenNthCalledWith( - 1, - ['ws://localhost:51233', 'ws://localhost:443'], - { - tryAllNodes: true, - }, - ) + expect(XrplClient).toHaveBeenNthCalledWith(1, ['ws://localhost:51233'], { + tryAllNodes: true, + }) expect((client as any).p2pSocket).not.toBeDefined() })