2021-10-21 22:11:12 +02:00
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
|
|
|
|
const cryptocurrencies = require('cryptocurrencies');
|
|
|
|
|
|
|
|
const customCryptocurrencies = require('./custom-cryptocurrencies.json');
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class CryptocurrencyService {
|
|
|
|
private combinedCryptocurrencies: string[];
|
|
|
|
|
|
|
|
public constructor() {}
|
|
|
|
|
2021-12-18 09:04:52 +01:00
|
|
|
public isCryptocurrency(aSymbol = '') {
|
2021-10-21 22:11:12 +02:00
|
|
|
const cryptocurrencySymbol = aSymbol.substring(0, aSymbol.length - 3);
|
|
|
|
return this.getCryptocurrencies().includes(cryptocurrencySymbol);
|
|
|
|
}
|
|
|
|
|
|
|
|
private getCryptocurrencies() {
|
|
|
|
if (!this.combinedCryptocurrencies) {
|
|
|
|
this.combinedCryptocurrencies = [
|
|
|
|
...cryptocurrencies.symbols(),
|
|
|
|
...Object.keys(customCryptocurrencies)
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.combinedCryptocurrencies;
|
|
|
|
}
|
|
|
|
}
|