Skip to content

Commit

Permalink
feat: fix minor issues of crwodfunding command
Browse files Browse the repository at this point in the history
  • Loading branch information
b00f committed Jan 9, 2025
1 parent 92b2a92 commit ee0bb17
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 21 deletions.
4 changes: 2 additions & 2 deletions internal/engine/command/crowdfund/crowdfund.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/engine/command/crowdfund/crowdfund.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *CrowdfundCmd) GetCommand() *command.Command {
purchaseChoices := []command.Choice{}
for index, pkg := range activeCampaign.Packages {
choice := command.Choice{
Name: pkg.Name,
Name: fmt.Sprintf("%s (%d USDT to %s)", pkg.Name, pkg.USDAmount, pkg.PACAmount),
Value: fmt.Sprintf("%d", index+1),
}

Expand Down
2 changes: 1 addition & 1 deletion internal/engine/command/crowdfund/crowdfund.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ sub_commands:
input_box: Choice
optional: false
result_template: |
Your purchase of {{ .purchase.USDAmount }} USDT to receive {{ .purchase.PACAmount }} PAC successfully registered in our database.
Your purchase of {{ .purchase.USDAmount }} USDT to receive {{ .purchase.PACAmount }} successfully registered in our database.
Please visit {{ .paymentLink }} to make the payment.
Once the payment is done, you can claim your PAC coins using "claim" command.
Expand Down
24 changes: 9 additions & 15 deletions internal/engine/command/crowdfund/purchase.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,22 @@ func (c *CrowdfundCmd) purchaseHandler(
}
pkg := activeCampaign.Packages[pkgIndex]

purchase := &entity.CrowdfundPurchase{
UserID: user.ID,
USDAmount: pkg.USDAmount,
PACAmount: pkg.PACAmount,
}
err := c.db.AddCrowdfundPurchase(purchase)
if err != nil {
log.Error("database failed", "error", err, "purchase", purchase)

return cmd.RenderInternalFailure()
}

orderID := fmt.Sprintf("crowdfund/%d", purchase.ID)
orderID := fmt.Sprintf("crowdfund/%d", user.ID)
invoiceID, err := c.nowPayments.CreateInvoice(pkg.USDAmount, orderID)
if err != nil {
log.Error("NowPayments failed", "error", err, "orderID", orderID)

return cmd.RenderInternalFailure()
}

purchase.InvoiceID = invoiceID
err = c.db.UpdateCrowdfundPurchase(purchase)
purchase := &entity.CrowdfundPurchase{
UserID: user.ID,
USDAmount: pkg.USDAmount,
PACAmount: pkg.PACAmount,
InvoiceID: invoiceID,
}

err = c.db.AddCrowdfundPurchase(purchase)
if err != nil {
log.Error("database failed", "error", err, "purchase", purchase)

Expand Down
4 changes: 2 additions & 2 deletions pkg/nowpayments/nowpayments.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ func (s *NowPayments) IsPaid(invoiceID string) (bool, error) {
}

func (s *NowPayments) getJWTToken() (string, error) {
url := fmt.Sprintf("%v/v1/auth", s.apiURL)
jsonStr := fmt.Sprintf(`{"email":"%v","password":"%v"}`, s.username, s.password)
url := fmt.Sprintf("%s/v1/auth", s.apiURL)
jsonStr := fmt.Sprintf(`{"email":%q,"password":%q}`, s.username, s.password)
req, err := http.NewRequestWithContext(s.ctx, http.MethodPost, url, bytes.NewBufferString(jsonStr))
if err != nil {
return "", err
Expand Down

0 comments on commit ee0bb17

Please sign in to comment.