Skip to content

Commit

Permalink
fix(wallet): fix formatting of unlimited token allowance
Browse files Browse the repository at this point in the history
  • Loading branch information
onyb committed Jun 21, 2022
1 parent 8ea9e5c commit 235d527
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {
} from '../constants/magics'

// Utils
import { getLocale } from '$web-common/locale'
import Amount from '../../utils/amount'
import { getLocale } from '../../../common/locale'

// Hooks
import usePricing from './pricing'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ const PortfolioTransactionItem = (props: Props) => {
return (
<DetailRow>
<DetailTextDark>
{toProperCase(text)} {transactionDetails.value}{' '}
{toProperCase(text)} {
transactionDetails.isApprovalUnlimited
? getLocale('braveWalletTransactionApproveUnlimited')
: transactionDetails.value
}{' '}
<AddressOrAsset onClick={onAssetClick(transactionDetails.symbol)}>
{transactionDetails.symbol}
</AddressOrAsset> -{' '}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ function ConfirmTransactionPanel ({
onSave={onEditAllowanceSave}
proposedAllowance={transactionDetails.valueExact}
symbol={transactionDetails.symbol}
decimals={transactionDetails.decimals}
approvalTarget={transactionDetails.approvalTargetLabel || ''}
isApprovalUnlimited={transactionDetails.isApprovalUnlimited || false}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react'
import Radio from 'brave-ui/components/formControls/radio'

import { getLocale } from '../../../../common/locale'
import { NavButton, Panel } from '../'
// Utils
import { getLocale } from '$web-common/locale'

// Styled Components
import { NavButton, Panel } from '../'
import {
StyledWrapper,
FormColumn,
Expand All @@ -15,13 +16,6 @@ import {
AllowanceContent,
AllowanceOption
} from './style'
import Amount from '../../../utils/amount'
import { MAX_UINT256 } from '../../../common/constants/magics'

export enum MaxPriorityPanels {
setSuggested = 0,
setCustom = 1
}

type AllowanceTypes =
| 'proposed'
Expand All @@ -32,8 +26,8 @@ export interface Props {
onSave: (allowance: string) => void
proposedAllowance: string
symbol: string
decimals: number
approvalTarget: string
isApprovalUnlimited: boolean
}

const EditAllowance = (props: Props) => {
Expand All @@ -46,7 +40,7 @@ const EditAllowance = (props: Props) => {
proposedAllowance,
approvalTarget,
symbol,
decimals
isApprovalUnlimited
} = props

const toggleAllowanceRadio = (key: AllowanceTypes) => {
Expand All @@ -67,11 +61,10 @@ const EditAllowance = (props: Props) => {
}, [allowanceType, customAllowance])

const formattedProposedAllowance = React.useMemo(() => {
const wrappedAmount = new Amount(proposedAllowance)
return wrappedAmount.multiplyByDecimals(decimals).eq(MAX_UINT256)
return isApprovalUnlimited
? getLocale('braveWalletTransactionApproveUnlimited')
: proposedAllowance
}, [proposedAllowance])
}, [proposedAllowance, isApprovalUnlimited])

return (
<Panel
Expand Down
1 change: 1 addition & 0 deletions components/brave_wallet_ui/stories/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ provideStrings({
braveWalletTransactionRetry: 'Retry transaction',
braveWalletTransactionPlaceholder: 'Transactions will appear here',
braveWalletTransactionApproveUnlimited: 'Unlimited',
braveWalletApprovalTransactionIntent: 'approve',

// Edit Gas
braveWalletEditGasTitle1: 'Max priority fee',
Expand Down
2 changes: 1 addition & 1 deletion components/resources/wallet_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@
<message name="IDS_BRAVE_WALLET_SIGN_TYPED_MESSAGE_CHAIN_ID_MISMATCH" desc="Sign typed message error"><ph name="ADDRESS">chainId $1<ex>1</ex></ph> is not current network</message>
<message name="IDS_BRAVE_WALLET_UNLOCK_ERROR" desc="Connect hardware wallet panel, error when device unlock failed">Unable to unlock device, try to reconnect</message>
<message name="IDS_BRAVE_WALLET_UNKNOWN_SCHEME_ERROR" desc="Connect hardware wallet panel, error when requested unsupported scheme for device">Internal error, unknown scheme</message>
<message name="IDS_BRAVE_WALLET_APPROVAL_TRANSACTION_INTENT" desc="Token approval transaction description">approved</message>
<message name="IDS_BRAVE_WALLET_APPROVAL_TRANSACTION_INTENT" desc="Token approval transaction description">approve</message>
<message name="IDS_BRAVE_WALLET_LEDGER_VALIDATION_ERROR" desc="Ledger signature validation error text">Ledger: The signature doesnt match the right address</message>
<message name="IDS_BRAVE_WALLET_HARDWARE_ACCOUNT_NOT_FOUND_ERROR" desc="Hardware account not found error message">Hardware account not found</message>
<message name="IDS_BRAVE_WALLET_IMPORT_JSON_ERROR" desc="Importer error message">JSON data is not expected</message>
Expand Down

0 comments on commit 235d527

Please sign in to comment.