Skip to content

Commit

Permalink
819 3 retrocompatibility allow edit fees (#832)
Browse files Browse the repository at this point in the history
* don't allow fee edition by default

* web: cypress: comment a failing test (2)

* Fix Faulty Cypress Test

* web: cypress: uncomment

---------

Co-authored-by: pivi <[email protected]>
  • Loading branch information
Thykof and pivilartisant authored Nov 8, 2023
1 parent 17d7f7c commit 11994a0
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 103 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ web-frontend/cypress-visual-report
web-frontend/cypress/screenshots
web-frontend/cypress-visual-screenshots/comparison
web-frontend/cypress-visual-screenshots/diff
web-frontend/cypress/downloads
documentation/node_modules
documentation/diag*.svg
documentation/*.html
Expand Down
16 changes: 16 additions & 0 deletions api/server/restapi/embedded_spec.go

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

50 changes: 47 additions & 3 deletions api/server/restapi/operations/sign_parameters.go

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

16 changes: 16 additions & 0 deletions api/server/restapi/operations/sign_urlbuilder.go

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

7 changes: 7 additions & 0 deletions api/walletApi-V0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ paths:
x-nullable: false
schema:
$ref: "#/definitions/SignRequest"
- in: query
name: allow-fee-edition
type: boolean
required: false
default: false
description: Whether to allow user to edit the fee value in the sign prompt.
x-nullable: true
produces:
- application/json
responses:
Expand Down
24 changes: 12 additions & 12 deletions internal/handler/wallet/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type PromptRequestSignData struct {
RecipientNickname string
Amount string
PlainText string
AllowFeeEdition bool
}

// NewSign instantiates a sign Handler
Expand All @@ -72,7 +73,7 @@ func (w *walletSign) Handle(params operations.SignParams) middleware.Responder {
return errResp
}

promptRequest, fees, err := w.getPromptRequest(params.Body.Operation.String(), acc, params.Body.Description)
promptRequest, fees, err := w.getPromptRequest(params, acc, params.Body.Description)
if err != nil {
return newErrorResponse(fmt.Sprintf("Error: %v", err.Error()), errorSignDecodeMessage, http.StatusBadRequest)
}
Expand Down Expand Up @@ -221,22 +222,15 @@ func prepareOperation(acc *account.Account, fees uint64, operationB64 string, op
return operation, msgToSign, nil
}

func (w *walletSign) getPromptRequest(msgToSign string, acc *account.Account, description string) (*prompt.PromptRequest, uint64, error) {
var opType uint64
var err error

addressBytes, err := acc.Address.MarshalText()
if err != nil {
return nil, 0, fmt.Errorf("failed to marshal address: %w", err)
}
address := string(addressBytes)
func (w *walletSign) getPromptRequest(params operations.SignParams, acc *account.Account, description string) (*prompt.PromptRequest, uint64, error) {
msgToSign := params.Body.Operation.String()

decodedMsg, fees, _, err := sendoperation.DecodeMessage64(msgToSign)
if err != nil {
return nil, 0, fmt.Errorf("failed to decode transaction message: %w", err)
}

opType, err = sendoperation.DecodeOperationType(decodedMsg)
opType, err := sendoperation.DecodeOperationType(decodedMsg)
if err != nil {
return nil, 0, fmt.Errorf("failed to decode operation ID: %w", err)
}
Expand Down Expand Up @@ -264,11 +258,17 @@ func (w *walletSign) getPromptRequest(msgToSign string, acc *account.Account, de
return nil, 0, fmt.Errorf("failed to decode message of operation type: %d: %w", opType, err)
}

addressBytes, err := acc.Address.MarshalText()
if err != nil {
return nil, 0, fmt.Errorf("failed to marshal address: %w", err)
}

data.Description = description
data.Fees = strconv.FormatUint(fees, 10)
data.WalletAddress = address
data.WalletAddress = string(addressBytes)
data.Nickname = acc.Nickname
data.OperationType = int(opType)
data.AllowFeeEdition = *params.AllowFeeEdition

promptRequest := prompt.PromptRequest{
Action: walletapp.Sign,
Expand Down
2 changes: 2 additions & 0 deletions wails-frontend/src/pages/PasswordPromptHandler/Sign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface SignBodyProps {
PlainText: string;
DisplayData: boolean;
Nickname: string;
AllowFeeEdition: boolean;
children?: React.ReactNode;
}

Expand Down Expand Up @@ -118,6 +119,7 @@ export function Sign() {
setFees,
isEditing,
setIsEditing,
allowFeeEdition: signData.AllowFeeEdition,
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
FiInfo,
FiRotateCcw,
} from 'react-icons/fi';
import { NumberFormatValues } from 'react-number-format';

import Intl from '@/i18n/i18n';
import { formatStandard, masToken } from '@/utils';
Expand All @@ -27,13 +28,21 @@ export interface OperationCostProps {
setFees: (fees: string) => void;
isEditing?: boolean;
setIsEditing: (isEditing: boolean) => void;
allowFeeEdition: boolean;
}

export function OperationCost(props: OperationCostProps) {
const hideCoins = props.coins === undefined;

const coins = toMAS(props.coins || 0).toFixed(9);
const { fees, setFees, defaultFees, isEditing, setIsEditing } = props;
const {
fees,
setFees,
defaultFees,
isEditing,
setIsEditing,
allowFeeEdition,
} = props;

const [operationCost, setOperationCost] = useState(computeCost());

Expand Down Expand Up @@ -63,6 +72,29 @@ export function OperationCost(props: OperationCostProps) {
return new BigNumber(coins).plus(new BigNumber(fees)).toFixed(9);
}

const feeEditionButtonsRow = allowFeeEdition ? (
<div className="flex justify-end gap-1">
{isEditing ? (
<>
<button className="flex hover:cursor-pointer" onClick={handleConfirm}>
<FiCheck size={16} className="mr-1" />
{Intl.t('password-prompt.sign.confirm-fees')}
</button>
<p className="px-1 hover:cursor-default">|</p>
<button className="flex hover:cursor-pointer" onClick={handleReset}>
<FiRotateCcw size={16} className="mr-1" />
{Intl.t('password-prompt.sign.reset-fees')}
</button>
</>
) : (
<button className="flex hover:cursor-pointer" onClick={handleEdit}>
<FiEdit2 size={16} className="mr-1" />
{Intl.t('password-prompt.sign.edit-fees')}
</button>
)}
</div>
) : null;

return (
<div className="w-full">
<div className="flex w-full justify-between pb-2">
Expand Down Expand Up @@ -107,7 +139,9 @@ export function OperationCost(props: OperationCostProps) {
customClass="mas-caption"
disabled={!isEditing}
value={fees}
onValueChange={(event: any) => setFees(event.value)}
onValueChange={(event: NumberFormatValues) =>
setFees(event.value)
}
/>
</div>
{!hideCoins && (
Expand All @@ -133,35 +167,7 @@ export function OperationCost(props: OperationCostProps) {
/>
</div>
)}
<div className="flex justify-end gap-1">
{isEditing ? (
<>
<button
className="flex hover:cursor-pointer"
onClick={handleConfirm}
>
<FiCheck size={16} className="mr-1" />
{Intl.t('password-prompt.sign.confirm-fees')}
</button>
<p className="px-1 hover:cursor-default">|</p>
<button
className="flex hover:cursor-pointer"
onClick={handleReset}
>
<FiRotateCcw size={16} className="mr-1" />
{Intl.t('password-prompt.sign.reset-fees')}
</button>
</>
) : (
<button
className="flex hover:cursor-pointer"
onClick={handleEdit}
>
<FiEdit2 size={16} className="mr-1" />
{Intl.t('password-prompt.sign.edit-fees')}
</button>
)}
</div>
{feeEditionButtonsRow}
</div>
</AccordionContent>
</AccordionCategory>
Expand Down
Loading

0 comments on commit 11994a0

Please sign in to comment.