Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
Wire cmd command; fix currency ticker for internal payments
Browse files Browse the repository at this point in the history
  • Loading branch information
0xBuzzLightyear committed Dec 17, 2023
1 parent 2d004fe commit c9ed558
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
27 changes: 25 additions & 2 deletions cmd/topup_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/oxygenpay/oxygen/internal/app"
"github.com/oxygenpay/oxygen/internal/money"
"github.com/oxygenpay/oxygen/internal/service/processing"
"github.com/oxygenpay/oxygen/internal/service/wallet"
"github.com/oxygenpay/oxygen/internal/util"
"github.com/samber/lo"
Expand Down Expand Up @@ -43,6 +44,7 @@ func topupBalance(_ *cobra.Command, _ []string) {
blockchainService = service.Locator().BlockchainService()
merchantService = service.Locator().MerchantService()
walletService = service.Locator().WalletService()
processingService = service.Locator().ProcessingService()
logger = service.Logger()
exit = func(err error, message string) { logger.Fatal().Err(err).Msg(message) }
)
Expand All @@ -67,6 +69,9 @@ func topupBalance(_ *cobra.Command, _ []string) {
exit(nil, "comment should not be empty")
}

isTest := *topupBalanceArgs.IsTest
comment := *topupBalanceArgs.Comment

// 2. Locate system balance
balances, err := walletService.ListAllBalances(ctx, wallet.ListAllBalancesOpts{WithSystemBalances: true})
if err != nil {
Expand All @@ -75,7 +80,7 @@ func topupBalance(_ *cobra.Command, _ []string) {

systemBalance, found := lo.Find(balances[wallet.EntityTypeSystem], func(b *wallet.Balance) bool {
tickerMatches := b.Currency == currency.Ticker
networkMatches := b.NetworkID == currency.ChooseNetwork(*topupBalanceArgs.IsTest)
networkMatches := b.NetworkID == currency.ChooseNetwork(isTest)

return tickerMatches && networkMatches
})
Expand All @@ -102,7 +107,25 @@ func topupBalance(_ *cobra.Command, _ []string) {
// 4. Perform topup
logger.Info().Msg("Sending...")

// todo
input := processing.TopupInput{
Currency: currency,
Amount: amount,
Comment: comment,
IsTest: isTest,
}

out, err := processingService.TopupMerchantFromSystem(ctx, merchant.ID, input)
if err != nil {
exit(err, "unable to topup the balance")
}

logger.
Info().
Int64("payment.id", out.Payment.ID).
Int64("tx.id", out.Transaction.ID).
Str("tx.usd_amount", out.Transaction.USDAmount.String()).
Str("merchant.balance", out.MerchantBalance.Amount.String()).
Msg("Done")
}

func topupBalanceSetup(cmd *cobra.Command) {
Expand Down
2 changes: 1 addition & 1 deletion internal/service/processing/service_topup.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (s *Service) TopupMerchantFromSystem(ctx context.Context, merchantID int64,
paymentProps := payment.CreateInternalPaymentProps{
MerchantOrderUUID: uuid.New(),
Money: in.Amount,
Description: fmt.Sprintf("Internal topup of %s %s (%s)", in.Amount.String(), in.Currency.Ticker, in.Comment),
Description: fmt.Sprintf("*internal* topup of %s %s (%s)", in.Amount.String(), in.Currency.Ticker, in.Comment),
IsTest: in.IsTest,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ const emptyState: Payment = {

const b = bevis("payment-desc-card");

const displayPrice = (record: Payment) => {
let ticker = record.currency + " ";
if (record.currency in CURRENCY_SYMBOL && CURRENCY_SYMBOL[record.currency] !== "") {
ticker = CURRENCY_SYMBOL[record.currency];
}

return ticker + record.price;
};

const PaymentDescCard: React.FC<Props> = ({data, openNotificationFunc}) => {
React.useEffect(() => {
if (!data) {
Expand Down Expand Up @@ -59,7 +68,7 @@ const PaymentDescCard: React.FC<Props> = ({data, openNotificationFunc}) => {
{data.orderId ?? "Not provided"}
</Descriptions.Item>
<Descriptions.Item span={3} label={<span className={b("item-title")}>Price</span>}>
{`${CURRENCY_SYMBOL[data.currency]}${data.price}`}
{displayPrice(data)}
</Descriptions.Item>
<Descriptions.Item span={3} label={<span className={b("item-title")}>Description</span>}>
{data.description ?? "Not provided"}
Expand Down
15 changes: 10 additions & 5 deletions ui-dashboard/src/pages/payments-page/payments-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ import PaymentStatusLabel from "src/components/payment-status/payment-status";
import TimeLabel from "src/components/time-label/time-label";
import {sleep} from "src/utils";

const displayPrice = (record: Payment) => {
let ticker = record.currency + " ";
if (record.currency in CURRENCY_SYMBOL && CURRENCY_SYMBOL[record.currency] !== "") {
ticker = CURRENCY_SYMBOL[record.currency];
}

return ticker + record.price;
};

const columns: ColumnsType<Payment> = [
{
title: "Created At",
Expand All @@ -37,11 +46,7 @@ const columns: ColumnsType<Payment> = [
dataIndex: "price",
key: "price",
width: "min-content",
render: (_, record) => (
<span style={{whiteSpace: "nowrap"}}>
{`${record.currency in CURRENCY_SYMBOL ? CURRENCY_SYMBOL[record.currency] : ""}${record.price}`}
</span>
)
render: (_, record) => <span style={{whiteSpace: "nowrap"}}>{displayPrice(record)}</span>
},
{
title: "Order ID",
Expand Down

0 comments on commit c9ed558

Please sign in to comment.