mirror of https://github.com/ghostfolio/ghostfolio
Browse Source
* Add support for custom cryptocurrencies defined in database * Update changelogpull/6337/head
committed by
GitHub
5 changed files with 31 additions and 18 deletions
@ -1,9 +1,12 @@ |
|||
import { PropertyModule } from '@ghostfolio/api/services/property/property.module'; |
|||
|
|||
import { Module } from '@nestjs/common'; |
|||
|
|||
import { CryptocurrencyService } from './cryptocurrency.service'; |
|||
|
|||
@Module({ |
|||
providers: [CryptocurrencyService], |
|||
exports: [CryptocurrencyService] |
|||
exports: [CryptocurrencyService], |
|||
imports: [PropertyModule], |
|||
providers: [CryptocurrencyService] |
|||
}) |
|||
export class CryptocurrencyModule {} |
|||
|
|||
@ -1,31 +1,39 @@ |
|||
import { DEFAULT_CURRENCY } from '@ghostfolio/common/config'; |
|||
import { PropertyService } from '@ghostfolio/api/services/property/property.service'; |
|||
import { |
|||
DEFAULT_CURRENCY, |
|||
PROPERTY_CUSTOM_CRYPTOCURRENCIES |
|||
} from '@ghostfolio/common/config'; |
|||
|
|||
import { Injectable } from '@nestjs/common'; |
|||
import { Injectable, OnModuleInit } from '@nestjs/common'; |
|||
|
|||
const cryptocurrencies = require('../../assets/cryptocurrencies/cryptocurrencies.json'); |
|||
const customCryptocurrencies = require('../../assets/cryptocurrencies/custom.json'); |
|||
|
|||
@Injectable() |
|||
export class CryptocurrencyService { |
|||
export class CryptocurrencyService implements OnModuleInit { |
|||
private combinedCryptocurrencies: string[]; |
|||
|
|||
public isCryptocurrency(aSymbol = '') { |
|||
const cryptocurrencySymbol = aSymbol.substring(0, aSymbol.length - 3); |
|||
public constructor(private readonly propertyService: PropertyService) {} |
|||
|
|||
return ( |
|||
aSymbol.endsWith(DEFAULT_CURRENCY) && |
|||
this.getCryptocurrencies().includes(cryptocurrencySymbol) |
|||
public async onModuleInit() { |
|||
const customCryptocurrenciesFromDatabase = |
|||
await this.propertyService.getByKey<Record<string, string>>( |
|||
PROPERTY_CUSTOM_CRYPTOCURRENCIES |
|||
); |
|||
} |
|||
|
|||
private getCryptocurrencies() { |
|||
if (!this.combinedCryptocurrencies) { |
|||
this.combinedCryptocurrencies = [ |
|||
...Object.keys(cryptocurrencies), |
|||
...Object.keys(customCryptocurrencies) |
|||
...Object.keys(customCryptocurrencies), |
|||
...Object.keys(customCryptocurrenciesFromDatabase ?? {}) |
|||
]; |
|||
} |
|||
|
|||
return this.combinedCryptocurrencies; |
|||
public isCryptocurrency(aSymbol = '') { |
|||
const cryptocurrencySymbol = aSymbol.substring(0, aSymbol.length - 3); |
|||
|
|||
return ( |
|||
aSymbol.endsWith(DEFAULT_CURRENCY) && |
|||
this.combinedCryptocurrencies.includes(cryptocurrencySymbol) |
|||
); |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue