Skip to content

Commit

Permalink
fixup! Implement updateInfoPayload
Browse files Browse the repository at this point in the history
  • Loading branch information
samholmes committed Jan 3, 2025
1 parent 9326172 commit 73f930d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
8 changes: 2 additions & 6 deletions src/common/plugin/CurrencyPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { makeUtxoEngine } from '../utxobased/engine/UtxoEngine'
import { makeCurrencyTools } from './CurrencyTools'
import { makeEngineEmitter } from './EngineEmitter'
import { makePluginState } from './PluginState'
import { asInfoPayload, EngineConfig, InfoPayload, PluginInfo } from './types'
import { asInfoPayload, EngineConfig, PluginInfo } from './types'

let hasMemletBeenSet = false

Expand All @@ -30,13 +30,9 @@ export function makeCurrencyPlugin(
const currencyTools = makeCurrencyTools(io, pluginInfo)
const { defaultSettings, pluginId, currencyCode } = currencyInfo

let cachedInfoPayload: InfoPayload | undefined
const getInfoPayload = (): InfoPayload | undefined => cachedInfoPayload

const pluginState = makePluginState({
defaultSettings: asUtxoUserSettings(defaultSettings),
currencyCode,
getInfoPayload,
io,
log,
pluginId,
Expand Down Expand Up @@ -90,7 +86,7 @@ export function makeCurrencyPlugin(

async updateInfoPayload(infoPayload) {
try {
cachedInfoPayload = asInfoPayload(infoPayload)
pluginState.infoPayload = asInfoPayload(infoPayload)
} catch (_) {
log.warn('invalid infoPayload', infoPayload)
}
Expand Down
19 changes: 7 additions & 12 deletions src/common/plugin/PluginState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ interface JsonObject {
export interface PluginStateSettings {
currencyCode: string
defaultSettings: UtxoUserSettings
getInfoPayload: () => InfoPayload | undefined
io: EdgeIo
log: EdgeLog
pluginDisklet: Disklet
pluginId: string
}

export interface PluginState {
infoPayload: InfoPayload | undefined

addEngine: (engineProcessor: UtxoEngineProcessor) => void
removeEngine: (engineProcessor: UtxoEngineProcessor) => void
dumpData: () => JsonObject
Expand All @@ -52,13 +53,7 @@ export interface PluginState {
}

export function makePluginState(settings: PluginStateSettings): PluginState {
const {
defaultSettings,
getInfoPayload,
log,
pluginDisklet,
pluginId
} = settings
const { defaultSettings, log, pluginDisklet, pluginId } = settings

let engines: UtxoEngineProcessor[] = []
const memlet = makeMemlet(pluginDisklet)
Expand Down Expand Up @@ -112,20 +107,20 @@ export function makePluginState(settings: PluginStateSettings): PluginState {
})

const getInfoPayloadServers = async (): Promise<string[]> => {
const infoPayload = getInfoPayload()

if (infoPayload == null) {
if (instance.infoPayload == null) {
log.warn(`info server list list empty`)
return []
}

const servers = Object.keys(infoPayload.blockbookServers)
const servers = Object.keys(instance.infoPayload.blockbookServers)
log.warn(`info server list`, servers)

return servers
}

const instance: PluginState = {
infoPayload: undefined,

/**
* Begins notifying the engine of state changes. Used at connection time.
*/
Expand Down

0 comments on commit 73f930d

Please sign in to comment.