Skip to content

Commit

Permalink
Inject BASE_URL for SafeConfigService (#5)
Browse files Browse the repository at this point in the history
Add BASE_URL_PROVIDER, a provider that can be injected with @Inject('SAFE_CONFIG_BASE_URL') and has the value of the Safe Config service url
  • Loading branch information
fmrsabino authored Aug 8, 2022
1 parent 86b5ae7 commit acbd2c6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
9 changes: 7 additions & 2 deletions src/services/safe-config/safe-config.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import { HttpModule } from '@nestjs/axios';
import { Module } from '@nestjs/common';
import { SafeConfigService } from './safe-config.service';

const BASE_URL_PROVIDER = {
provide: 'SAFE_CONFIG_BASE_URL',
useValue: 'https://safe-config.gnosis.io', // TODO extract to a config file
};

@Module({
imports: [HttpModule],
providers: [SafeConfigService],
exports: [SafeConfigService],
providers: [SafeConfigService, BASE_URL_PROVIDER],
exports: [SafeConfigService, BASE_URL_PROVIDER],
})
export class SafeConfigModule {}
18 changes: 9 additions & 9 deletions src/services/safe-config/safe-config.service.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { HttpService } from '@nestjs/axios';
import { Injectable } from '@nestjs/common';
import { Inject, Injectable } from '@nestjs/common';
import { SafeConfigPage } from './entities/page.entity';
import { SafeConfigChain } from './entities/chain.entity';

@Injectable()
export class SafeConfigService {
// TODO: extract base URL to constructor
constructor(private readonly httpService: HttpService) {}
constructor(
@Inject('SAFE_CONFIG_BASE_URL') private readonly baseUrl,
private readonly httpService: HttpService,
) {}

async getChains(): Promise<SafeConfigPage<SafeConfigChain>> {
try {
const response = await this.httpService.axiosRef.get(
`https://safe-config.gnosis.io/api/v1/chains`,
);
const url = this.baseUrl + '/api/v1/chains';
const response = await this.httpService.axiosRef.get(url);
return response.data;
} catch (error) {
console.log(error);
Expand All @@ -22,9 +23,8 @@ export class SafeConfigService {

async getChain(chainId: string): Promise<SafeConfigChain> {
try {
const response = await this.httpService.axiosRef.get(
`https://safe-config.gnosis.io/api/v1/chains/${chainId}`,
);
const url = this.baseUrl + `/api/v1/chains/${chainId}`;
const response = await this.httpService.axiosRef.get(url);
return response.data;
} catch (error) {
console.log(error);
Expand Down

0 comments on commit acbd2c6

Please sign in to comment.