Skip to content

Commit

Permalink
fix transfer and roll edit fees, fix roll side (#838)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thykof authored Nov 9, 2023
1 parent cf6b01a commit d346607
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/handler/wallet/rolls.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (t *tradeRolls) Handle(params operations.TradeRollsParams) middleware.Respo

password := output.Password

operation, err := doTradeRolls(acc, password, amount, fee, opType, t.massaClient)
operation, err := doTradeRolls(acc, password, amount, output.Fees, opType, t.massaClient)
if err != nil {
msg := fmt.Sprintf("error %sing rolls coin: %v", *params.Body.Side, err.Error())

Expand All @@ -115,7 +115,7 @@ func doTradeRolls(
massaClient network.NodeFetcherInterface,
) (*sendOperation.OperationResponse, error) {
var operation sendOperation.Operation
if opType == sellrolls.OpType {
if opType == buyrolls.OpType {
operation = buyrolls.New(amount)
} else {
operation = sellrolls.New(amount)
Expand Down
4 changes: 2 additions & 2 deletions internal/handler/wallet/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (t *transferCoin) Handle(params operations.TransferCoinParams) middleware.R
promptRequest := prompt.PromptRequest{
Action: walletapp.Sign,
Data: PromptRequestSignData{
Fees: string(params.Body.Fee),
Fees: strconv.FormatUint(fee, 10),
WalletAddress: address,
Nickname: acc.Nickname,
OperationType: int(transaction.OpType),
Expand All @@ -87,7 +87,7 @@ func (t *transferCoin) Handle(params operations.TransferCoinParams) middleware.R
password := output.Password

// create the transaction and send it to the network
operation, err := doTransfer(acc, password, amount, fee, *params.Body.RecipientAddress, t.massaClient)
operation, err := doTransfer(acc, password, amount, output.Fees, *params.Body.RecipientAddress, t.massaClient)
if err != nil {
msg := fmt.Sprintf("error transferring coin: %v", err.Error())

Expand Down
11 changes: 11 additions & 0 deletions internal/handler/wallet/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ func Test_transfer_handler(t *testing.T) {
assert.Equal(t, http.StatusNotFound, resp.Result().StatusCode)
})

t.Run("Transfer with invalid fee", func(t *testing.T) {
resp, err := handleHTTPRequest(handler, "POST", fmt.Sprintf("/api/accounts/%s/transfer", nickname), `{
"fee": "none",
"amount": "5",
"recipientAddress": "AU1eQkRhZZBa5VNc24fCejxgFDpe1FHChpwiUksQB9StNb3rWm6i"
}`)

assert.NoError(t, err)
assert.Equal(t, http.StatusBadRequest, resp.Result().StatusCode)
})

t.Run("Transfer with invalid amount", func(t *testing.T) {
resp, err := handleHTTPRequest(handler, "POST", fmt.Sprintf("/api/accounts/%s/transfer", nickname), `{
"fee": "1",
Expand Down

0 comments on commit d346607

Please sign in to comment.