Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use get or throw to get some env vars #189

Open
wants to merge 3 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ SMART_WALLETS_PORT=5007
SMART_WALLETS_TCP_PORT=8882
SMART_WALLETS_MONGO_URI=mongodb://mongo:27017/charge-smart-wallets
SMART_WALLETS_JWT_SECRET=smart_wallets_jwt_secret
INCOMING_TOKEN_TRANSFERS_WEBHOOK_ID=put_incoming_token_transfers_webhook_id_here
INCOMING_TOKEN_TRANSFERS_WEBHOOK_ID=
FUSE_WALLET_BACKEND_JWT=fuse_wallet_backend_jwt
CENTRIFUGO_URI=ws://centrifugo:8000/connection/websocket
CENTRIFUGO_JWT=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import configuration from '@app/apps-service/common/config/configuration'
useFactory: async (configService: ConfigService) => ({
headers: {
'Content-Type': 'application/json',
'API-SECRET': `${configService.get('CHARGE_SECRET_KEY')}`
'API-SECRET': `${configService.getOrThrow('CHARGE_SECRET_KEY')}`
}
}),
inject: [ConfigService]
Expand Down
5 changes: 3 additions & 2 deletions apps/charge-apps-service/src/charge-api/charge-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class ChargeApiService {
}

get chargeBaseUrl () {
return this.configService.get('CHARGE_BASE_URL')
return this.configService.getOrThrow('CHARGE_BASE_URL')
}

get unmarshalBaseUrl () {
Expand All @@ -38,7 +38,7 @@ export class ChargeApiService {
}

get chargePublicKey () {
return this.configService.get('CHARGE_PUBLIC_KEY')
return this.configService.getOrThrow('CHARGE_PUBLIC_KEY')
}

get chargeWebhookId () {
Expand Down Expand Up @@ -163,6 +163,7 @@ export class ChargeApiService {
}

async addWebhookAddress (params: { walletAddress: string, webhookId: string }) {
console.log('Adding address to the webhook...')
const url = `${this.chargeBaseUrl}/api/v0/notifications/webhook/add-addresses?apiKey=${this.chargePublicKey}`
const requestBody = {
webhookId: params.webhookId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@ import { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common'
import { JwtService } from '@nestjs/jwt'
import { arrayify, computeAddress, hashMessage, recoverPublicKey } from 'nestjs-ethers'
import { SmartWalletService } from '@app/smart-wallets-service/smart-wallets/interfaces/smart-wallets.interface'
import { NotificationsService } from '@app/api-service/notifications/notifications.service'
import { ConfigService } from '@nestjs/config'
import { ChargeApiService } from '@app/apps-service/charge-api/charge-api.service'
// import { ISmartWalletUser } from '@app/common/interfaces/smart-wallet.interface'
// import CentrifugoAPIService from '@app/common/services/centrifugo.service'

@Injectable()
export class SmartWalletsAAService implements SmartWalletService {
private readonly logger = new Logger(SmartWalletsAAService.name)

constructor (
private readonly jwtService: JwtService,
private readonly notificationsService: NotificationsService,
private configService: ConfigService,
private chargeApiService: ChargeApiService
// private readonly centrifugoAPIService: CentrifugoAPIService,
) { }

async auth (smartWalletsAuthDto: SmartWalletsAuthDto) {
Expand Down Expand Up @@ -51,8 +46,10 @@ export class SmartWalletsAAService implements SmartWalletService {
}

private async subscribeWalletToNotifications (walletAddress: string) {
console.log('Subscribing wallets to notifications...')

const webhookId =
this.configService.get('INCOMING_TOKEN_TRANSFERS_WEBHOOK_ID')
this.configService.getOrThrow('INCOMING_TOKEN_TRANSFERS_WEBHOOK_ID')

return this.chargeApiService.addWebhookAddress({ walletAddress, webhookId })
}
Expand Down