Skip to content

Commit

Permalink
Merge pull request #1916 from stakwork/fix/failed_payments_logs
Browse files Browse the repository at this point in the history
PR: Fix Payment For Bounty Titles with special characters
  • Loading branch information
elraphty authored Nov 6, 2024
2 parents 4e1dbaa + 6a46544 commit 3433b8c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 7 additions & 1 deletion handlers/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"log"
"net/http"
"net/url"
"strconv"
"sync"
"time"
Expand Down Expand Up @@ -612,7 +613,8 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request
// Get Bounty Assignee
assignee := h.db.GetPersonByPubkey(bounty.Assignee)

memoText := fmt.Sprintf("Payment For: %ss", bounty.Title)
memoData := fmt.Sprintf("Payment For: %ss", bounty.Title)
memoText := url.QueryEscape(memoData)
now := time.Now()

// If the v2contactkey is present
Expand All @@ -625,6 +627,8 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request
bodyData := utils.BuildV2KeysendBodyData(amount, assignee.OwnerPubKey, assignee.OwnerRouteHint, memoText)
jsonBody := []byte(bodyData)

log.Println("Payment Body Data", bodyData)

req, _ := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(jsonBody))
req.Header.Set("x-admin-token", config.V2BotToken)
req.Header.Set("Content-Type", "application/json")
Expand Down Expand Up @@ -798,6 +802,8 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request
bodyData := utils.BuildKeysendBodyData(amount, assignee.OwnerPubKey, assignee.OwnerRouteHint, memoText)
jsonBody := []byte(bodyData)

log.Println("Payment Body Data", bodyData)

req, _ := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(jsonBody))
req.Header.Set("x-user-token", config.RelayAuthKey)
req.Header.Set("Content-Type", "application/json")
Expand Down
7 changes: 5 additions & 2 deletions handlers/bounty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"log"
"net/http"
"net/http/httptest"
"net/url"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -1418,7 +1419,8 @@ func TestMakeBountyPayment(t *testing.T) {
bHandler2.getSocketConnections = mockGetSocketConnections
bHandler2.userHasAccess = mockUserHasAccessTrue

memoText := fmt.Sprintf("Payment For: %ss", bounty.Title)
memoData := fmt.Sprintf("Payment For: %ss", bounty.Title)
memoText := url.QueryEscape(memoData)

expectedUrl := fmt.Sprintf("%s/payment", config.RelayUrl)
expectedBody := fmt.Sprintf(`{"amount": %d, "destination_key": "%s", "text": "memotext added for notification", "data": "%s"}`, bountyAmount, person.OwnerPubKey, memoText)
Expand Down Expand Up @@ -1466,7 +1468,8 @@ func TestMakeBountyPayment(t *testing.T) {
bHandler.getSocketConnections = mockGetSocketConnections
bHandler.userHasAccess = mockUserHasAccessTrue

memoText := fmt.Sprintf("Payment For: %ss", bounty.Title)
memoData := fmt.Sprintf("Payment For: %ss", bounty.Title)
memoText := url.QueryEscape(memoData)

expectedUrl := fmt.Sprintf("%s/payment", config.RelayUrl)
expectedBody := fmt.Sprintf(`{"amount": %d, "destination_key": "%s", "text": "memotext added for notification", "data": "%s"}`, bountyAmount, person.OwnerPubKey, memoText)
Expand Down

0 comments on commit 3433b8c

Please sign in to comment.