mirror of https://github.com/ghostfolio/ghostfolio
8 changed files with 49 additions and 25 deletions
@ -1,9 +1,12 @@ |
|||||
|
import { PropertyModule } from '@ghostfolio/api/services/property/property.module'; |
||||
|
|
||||
import { Module } from '@nestjs/common'; |
import { Module } from '@nestjs/common'; |
||||
|
|
||||
import { CryptocurrencyService } from './cryptocurrency.service'; |
import { CryptocurrencyService } from './cryptocurrency.service'; |
||||
|
|
||||
@Module({ |
@Module({ |
||||
providers: [CryptocurrencyService], |
exports: [CryptocurrencyService], |
||||
exports: [CryptocurrencyService] |
imports: [PropertyModule], |
||||
|
providers: [CryptocurrencyService] |
||||
}) |
}) |
||||
export class CryptocurrencyModule {} |
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 cryptocurrencies = require('../../assets/cryptocurrencies/cryptocurrencies.json'); |
||||
const customCryptocurrencies = require('../../assets/cryptocurrencies/custom.json'); |
const customCryptocurrencies = require('../../assets/cryptocurrencies/custom.json'); |
||||
|
|
||||
@Injectable() |
@Injectable() |
||||
export class CryptocurrencyService { |
export class CryptocurrencyService implements OnModuleInit { |
||||
private combinedCryptocurrencies: string[]; |
private combinedCryptocurrencies: string[]; |
||||
|
|
||||
public isCryptocurrency(aSymbol = '') { |
public constructor(private readonly propertyService: PropertyService) {} |
||||
const cryptocurrencySymbol = aSymbol.substring(0, aSymbol.length - 3); |
|
||||
|
|
||||
return ( |
public async onModuleInit() { |
||||
aSymbol.endsWith(DEFAULT_CURRENCY) && |
const customCryptocurrenciesFromDatabase = |
||||
this.getCryptocurrencies().includes(cryptocurrencySymbol) |
await this.propertyService.getByKey<Record<string, string>>( |
||||
|
PROPERTY_CUSTOM_CRYPTOCURRENCIES |
||||
); |
); |
||||
} |
|
||||
|
|
||||
private getCryptocurrencies() { |
|
||||
if (!this.combinedCryptocurrencies) { |
|
||||
this.combinedCryptocurrencies = [ |
this.combinedCryptocurrencies = [ |
||||
...Object.keys(cryptocurrencies), |
...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