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

PR: Fix Payment For Bounty Titles with special characters #1916

Merged
merged 3 commits into from
Nov 6, 2024
Merged
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
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
Loading