Skip to content

Commit

Permalink
Merge pull request #412 from EdgeApp/william/nownodes-fixes
Browse files Browse the repository at this point in the history
NowNodes fixes
  • Loading branch information
swansontec authored Aug 29, 2024
2 parents dc61703 + 1e17239 commit 4a58791
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- fixed: Update NowNodes URL's for DASH, GRS, and FIRO.

## 3.3.0 (2024-08-20)

- added: Support for blockbook server connections with "%{key-name}" key parameters
Expand Down
2 changes: 1 addition & 1 deletion src/common/utxobased/info/dash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const currencyInfo: EdgeCurrencyInfo = {
'wss://dash3.trezor.io',
'wss://dash4.trezor.io',
'wss://dash5.trezor.io',
'wss://dashbook.nownodes.io/wss/%{nowNodesApiKey}'
'wss://dash.nownodes.io/wss/%{nowNodesApiKey}'
],
enableCustomServers: false
},
Expand Down
2 changes: 1 addition & 1 deletion src/common/utxobased/info/groestlcoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const engineInfo: EngineInfo = {
serverConfigs: [
{
type: 'blockbook-nownode',
uris: ['https://grsbook.nownodes.io']
uris: ['https://grs.nownodes.io']
}
],
formats: ['bip49', 'bip84', 'bip44', 'bip32'],
Expand Down
2 changes: 1 addition & 1 deletion src/common/utxobased/info/zcoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const currencyInfo: EdgeCurrencyInfo = {
customFeeSettings: ['satPerByte'],
blockbookServers: [
'wss://blockbook.firo.org',
'wss://firobook.nownodes.io/wss/%{nowNodesApiKey}'
'wss://firo.nownodes.io/wss/%{nowNodesApiKey}'
],
enableCustomServers: false
},
Expand Down
22 changes: 11 additions & 11 deletions src/common/utxobased/network/Socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function makeSocket(uri: string, config: SocketConfig): Socket {
let connected = false
let cancelConnect = false
const timeout: number = 1000 * (config.timeout ?? 30)
let trackedError: unknown | undefined
let trackedError: unknown
let timer: NodeJS.Timeout

const handleError = (e: unknown): void => {
Expand All @@ -153,14 +153,14 @@ export function makeSocket(uri: string, config: SocketConfig): Socket {
removeIdFromQueue(socketQueueId)
}

const onSocketClose = (): void => {
const onSocketClose = (code: number): void => {
const errObj =
trackedError != null
? trackedError instanceof Error
? trackedError
: new Error(String(trackedError))
: new Error('Socket closed without error')
log.warn(`onSocketClose with server ${uri}: ${errObj.message}`)
trackedError == null
? new Error('Socket closed without error')
: trackedError instanceof Error
? trackedError
: new Error(String(trackedError))
log.warn(`onSocketClose with server ${uri}: ${code} ${errObj.message}`)
clearTimeout(timer)
connected = false
socket = null
Expand All @@ -174,8 +174,8 @@ export function makeSocket(uri: string, config: SocketConfig): Socket {
pendingRequests = {}
try {
emitter.emit(SocketEvent.CONNECTION_CLOSE, uri, errObj)
} catch (e) {
log.error(e.message)
} catch (e: unknown) {
log.error(String(e))
}
}

Expand Down Expand Up @@ -403,7 +403,7 @@ export function makeSocket(uri: string, config: SocketConfig): Socket {
},
onMessage: onMessage,
onError: err => {
trackedError = new Error(String(err))
trackedError = err
},
onClose: onSocketClose
}
Expand Down
4 changes: 2 additions & 2 deletions src/common/utxobased/network/nodejsWS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export function setupWS(
ws.on('error', error => {
callbacks.onError(error)
})
ws.on('close', _event => {
callbacks.onClose()
ws.on('close', (code: number, reason: string) => {
callbacks.onClose(code, reason)
})

return {
Expand Down
9 changes: 7 additions & 2 deletions src/common/utxobased/network/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
export interface InnerSocketCallbacks {
onError: (error?: unknown) => void
/**
* Called when the socket closes.
* See rfc6455 section 7.4.1 for status codes.
*/
onClose: (code: number, reason: string) => void

onError: (error?: Event | Error) => void
onMessage: (message: string) => void
onClose: (error?: Error) => void
onOpen: () => void
}

Expand Down
4 changes: 2 additions & 2 deletions src/common/utxobased/network/windowWS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export function setupBrowser(
socket.onerror = event => {
callbacks.onError(event)
}
socket.onclose = () => {
callbacks.onClose()
socket.onclose = event => {
callbacks.onClose(event.code, event.reason)
}

return {
Expand Down

0 comments on commit 4a58791

Please sign in to comment.