Skip to content

Commit

Permalink
chore(realtime): add 'DevExchangeConfig' type to calling code
Browse files Browse the repository at this point in the history
  • Loading branch information
vindard committed Mar 18, 2024
1 parent 4bab0e7 commit 65184a2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion realtime/src/app/realtime/index.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type RefreshRealtimeDataArgs = {
currency: CurrencyCode
exchange: ExchangeConfig
exchange: DevExchangeConfig | ExchangeConfig
}

type RefreshDataCallbackArgs = {
Expand Down
2 changes: 1 addition & 1 deletion realtime/src/app/realtime/start-watchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const startWatcher = async ({
callback,
}: {
currency: CurrencyCode
exchange: ExchangeConfig
exchange: DevExchangeConfig | ExchangeConfig
callback?: RefreshDataCallback
}): Promise<ScheduledTask> => {
const task = async () => {
Expand Down
2 changes: 1 addition & 1 deletion realtime/src/config/index.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type RawExchangeConfig = {
quoteAlias: string[]
provider: string
cron: string
config: { [key: string]: string | number | boolean }
config: { [key: string]: string | number | boolean } | MockedConfig
}

type PartialExchangeConfig = {
Expand Down
24 changes: 16 additions & 8 deletions realtime/src/config/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const supportedCurrencies: FiatCurrency[] = yamlConfig.quotes.map((q) =>
export const defaultBaseCurrency: CurrencyCode = yamlConfig.base
export const defaultQuoteCurrency: FiatCurrency = supportedCurrencies[0]

export const getExchangesConfig = (): ExchangeConfig[] => {
export const getExchangesConfig = (): (DevExchangeConfig | ExchangeConfig)[] => {
// Set dev mode if dev config is present
if (yamlConfig.exchanges.find((e) => e.provider === "dev-mock")) {
yamlConfig.exchanges = yamlConfig.exchanges.filter((e) => e.provider === "dev-mock")
Expand Down Expand Up @@ -98,19 +98,27 @@ export const getExchangesConfig = (): ExchangeConfig[] => {
}
})

const rawExchangesConfig: ExchangeConfig[] = []
const rawExchangesConfig: (DevExchangeConfig | ExchangeConfig)[] = []
for (const config of enabledRawExchangesConfig) {
const newConfig = config.quote
.map<ExchangeConfig>((q, i) => ({
...config,
quote: q,
quoteAlias: config.quoteAlias[i],
}))
.map<DevExchangeConfig | ExchangeConfig>((q, i) =>
typeof config.config === "object" && "devMockPrice" in config.config
? ({
...config,
quote: q,
quoteAlias: config.quoteAlias[i],
} as DevExchangeConfig)
: ({
...config,
quote: q,
quoteAlias: config.quoteAlias[i],
} as ExchangeConfig),
)
.filter((c) => c.base !== c.quote)
rawExchangesConfig.push(...newConfig)
}

const exchangesConfig: ExchangeConfig[] = []
const exchangesConfig: (DevExchangeConfig | ExchangeConfig)[] = []
for (const config of rawExchangesConfig) {
let newConfigs = [config]
if (config.quote === "*" || config.quoteAlias === "*") {
Expand Down
4 changes: 3 additions & 1 deletion realtime/src/domain/exchanges/index.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ interface IExchangeService {
}

type ExchangeFactory = {
create(config: ExchangeConfig): Promise<IExchangeService | ExchangeServiceError>
create(
config: DevExchangeConfig | ExchangeConfig,
): Promise<IExchangeService | ExchangeServiceError>
}

0 comments on commit 65184a2

Please sign in to comment.