Skip to content
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
36 changes: 36 additions & 0 deletions dev/bruno/Flash GraphQL API/admin/cashout-notification-send.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
meta {
name: cashout-notification-send
type: graphql
seq: 2
}

post {
url: {{admin_url}}
body: graphql
auth: bearer
}

auth:bearer {
token: {{admin_token}}
}

body:graphql {
mutation CashoutNotificationSend($input: CashoutNotificationSendInput!) {
cashoutNotificationSend(input: $input) {
errors {
message
}
success
}
}
}

body:graphql:vars {
{
"input": {
"accountId": "165d0bea-ea3f-4f22-9b95-ebc09a75c133",
"amount": 100.0,
"currency": "JMD"
}
}
}
1 change: 1 addition & 0 deletions src/app/admin/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from "./update-user-phone"
// export * from "./send-admin-push-notification"
// export * from "./send-broadcast-notification"
export * from "./send-cashout-notification"

import { checkedToAccountUuid, checkedToUsername } from "@domain/accounts"
import { IdentityRepository } from "@services/kratos"
Expand Down
36 changes: 36 additions & 0 deletions src/app/admin/send-cashout-notification.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { getI18nInstance } from "@config"
import {
NotificationsServiceError,
} from "@domain/notifications"
import { MoneyAmount } from "@domain/shared"
import { AccountsRepository } from "@services/mongoose/accounts"
import { UsersRepository } from "@services/mongoose/users"
import { PushNotificationsService } from "@services/notifications/push-notifications"

const i18n = getI18nInstance();

export const sendCashoutNotification = async (
accountId: AccountUuid,
amount: MoneyAmount,
): Promise<true | ApplicationError> => {
const accountsRepo = AccountsRepository()
const account = await accountsRepo.findByUuid(accountId)
if (account instanceof Error) return account
const kratosUserId = account.kratosUserId

const usersRepo = UsersRepository()
const user = await usersRepo.findById(kratosUserId)
if (user instanceof Error) return user

const currency = amount.currencyCode

const result = PushNotificationsService().sendNotification({
deviceTokens: user.deviceTokens,
title: i18n.__({ phrase: "notification.cashout.title", locale: "en" }, { currency }),
body: i18n.__({ phrase: "notification.cashout.body", locale: "en" }, { amount: amount.i18n() }),
data: { amount: String(amount), currency },
})
if (result instanceof NotificationsServiceError) return result

return result
}
4 changes: 2 additions & 2 deletions src/app/offers/storage/Redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RedisCacheService } from "@services/cache"
import { CacheServiceError, CacheUndefinedError, OfferNotFound } from "@domain/cache"
import { baseLogger } from "@services/logger"
import { randomUUID } from "crypto"
import { JMDAmount, MoneyAmount, USDAmount } from "@domain/shared"
import { JMDAmount, MoneyAmount, USDAmount, toMoneyAmountFromJSON } from "@domain/shared"
import { CashoutDetails } from "../types"

/**
Expand All @@ -26,7 +26,7 @@ const OffersSerde = {
json,
(key: string, value: any) => {
if (['usd', 'jmd', 'fee'].includes(key.toLowerCase()) && Array.isArray(value)) {
return MoneyAmount.fromJSON(value as [string, string])
return toMoneyAmountFromJSON(value as [string, string])
}
if (key.toLowerCase() === 'amount' && typeof value === 'string') {
return BigInt(value);
Expand Down
6 changes: 5 additions & 1 deletion src/config/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
"bodyDisplayCurrency": "+{{baseCurrencyAmount}}{{baseCurrencyName}} ({{displayCurrencyAmount}})",
"title": "{{walletCurrency}} Transaction"
}
},
"cashout": {
"body": "Your cashout of {{amount}} has been deposited to your bank account.",
"title": "Cashout"
}
}
}
}
8 changes: 5 additions & 3 deletions src/domain/notifications/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ export const NotificationChannel = {
Push: "push",
} as const

export const GaloyNotificationCategories = {
export const FlashNotificationCategories = {
Payments: "Payments" as NotificationCategory,
Balance: "Balance" as NotificationCategory,
AdminPushNotification: "AdminPushNotification" as NotificationCategory,
Cashout: "Cashout" as NotificationCategory
} as const

export const checkedToNotificationCategory = (
notificationCategory: string,
): NotificationCategory | ValidationError => {
// TODO: add validation
if (!notificationCategory) {

const validNotificationCategories = Object.values(FlashNotificationCategories)
if (!validNotificationCategories.includes(notificationCategory as NotificationCategory)) {
return new InvalidNotificationSettingsError("Invalid notification category")
}

Expand Down
3 changes: 0 additions & 3 deletions src/domain/notifications/index.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ interface INotificationsService {
adminPushNotificationSend(
args: SendPushNotificationArgs,
): Promise<true | NotificationsServiceError>
adminPushNotificationFilteredSend(
args: SendFilteredPushNotificationArgs,
): Promise<true | NotificationsServiceError>
}

type NotificationChannel =
Expand Down
177 changes: 0 additions & 177 deletions src/domain/shared/MoneyAmount.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/domain/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ErrorLevel } from "./errors"
export * from "./primitives"
export * from "./calculator"
export * from "./amount"
export * from "./MoneyAmount"
export * from "./money"
export * from "./safe"
export * from "./errors"
export * from "./error-parsers"
Expand Down
35 changes: 35 additions & 0 deletions src/domain/shared/money/BTCAmount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Money, { Round } from "../bigint-money"
import { MoneyAmount } from "./MoneyAmount"
import { WalletCurrency } from "../primitives"
import { BigIntConversionError } from "../errors"

export class BtcAmount extends MoneyAmount {
currencyCode = WalletCurrency.Btc as WalletCurrency

private constructor(amount: Money | bigint | string | number) {
super(amount, WalletCurrency.Btc)
}

static sats(c: string): BtcAmount | BigIntConversionError {
try {
return new BtcAmount(c)
} catch (error) {
return new BigIntConversionError(error instanceof Error ? error.message : String(error))
}
}

asSats(precision: number = 0): string {
return this.money.toFixed(precision)
}

getInstance(amount: Money): this {
return new BtcAmount(amount) as this
}

i18n(): string {
return new Intl.NumberFormat("en", {
minimumFractionDigits: 0,
maximumFractionDigits: 0,
}).format(Number(this.asSats())) + " sats";
}
}
Loading