Skip to content

Commit

Permalink
refactor(wallet-mobile): refactored privacy
Browse files Browse the repository at this point in the history
  • Loading branch information
stackchain committed May 4, 2024
1 parent 74fb5c4 commit feacdef
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 36 deletions.
13 changes: 7 additions & 6 deletions apps/wallet-mobile/src/TxHistory/BalanceBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const BalanceBanner = React.forwardRef<ResetErrorRef>((_, ref) => {
const wallet = useSelectedWallet()
const styles = useStyles()
const primaryBalance = usePortfolioPrimaryBalance({wallet})
const {isPrivacyOff, togglePrivacyMode, privacyPlaceholder} = usePrivacyMode()
const {togglePrivacyMode} = usePrivacyMode()

return (
<View>
Expand All @@ -29,7 +29,7 @@ export const BalanceBanner = React.forwardRef<ResetErrorRef>((_, ref) => {

<TouchableOpacity onPress={() => togglePrivacyMode()} style={styles.button}>
<CenteredRow>
<Balance isPrivacyOff={isPrivacyOff} amount={primaryBalance} privacyPlaceholder={privacyPlaceholder} />
<Balance amount={primaryBalance} />
</CenteredRow>

<CenteredRow>
Expand All @@ -40,16 +40,17 @@ export const BalanceBanner = React.forwardRef<ResetErrorRef>((_, ref) => {
)
})

type BalanceProps = {isPrivacyOff: boolean; amount: Portfolio.Token.Amount; privacyPlaceholder: string}
const Balance = ({isPrivacyOff, amount, privacyPlaceholder}: BalanceProps) => {
type BalanceProps = {amount: Portfolio.Token.Amount; ignorePrivacy?: boolean}
const Balance = ({amount, ignorePrivacy}: BalanceProps) => {
const {isPrivacyOff, privacyPlaceholder} = usePrivacyMode()
const styles = useStyles()

const balance = React.useMemo(
() =>
!isPrivacyOff
isPrivacyOff || ignorePrivacy
? amountFormatter({template: '{{value}} {{ticker}}'})(amount)
: amountFormatter({template: `${privacyPlaceholder} {{ticker}}`})(amount),
[amount, isPrivacyOff, privacyPlaceholder],
[amount, ignorePrivacy, isPrivacyOff, privacyPlaceholder],
)

return (
Expand Down
6 changes: 3 additions & 3 deletions apps/wallet-mobile/src/TxHistory/LockedDeposit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import {usePrivacyMode} from '../features/Settings/PrivacyMode/PrivacyMode'
import {useSelectedWallet} from '../features/WalletManager/Context'
import globalMessages from '../i18n/global-messages'

export const LockedDeposit = () => {
export const LockedDeposit = ({ignorePrivacy = false}: {ignorePrivacy?: boolean}) => {
const wallet = useSelectedWallet()
const {isPrivacyOff, privacyPlaceholder} = usePrivacyMode()
const {lockedAsStorageCost} = usePortfolioPrimaryBreakdown({wallet})

const amount = React.useMemo(
() =>
!isPrivacyOff
isPrivacyOff || ignorePrivacy
? amountFormatter({template: '{{value}} {{ticker}}'})({
quantity: lockedAsStorageCost,
info: wallet.portfolioPrimaryTokenInfo,
Expand All @@ -26,7 +26,7 @@ export const LockedDeposit = () => {
quantity: 0n,
info: wallet.portfolioPrimaryTokenInfo,
}),
[isPrivacyOff, lockedAsStorageCost, privacyPlaceholder, wallet],
[ignorePrivacy, isPrivacyOff, lockedAsStorageCost, privacyPlaceholder, wallet.portfolioPrimaryTokenInfo],
)

return <FormattedAmount amount={amount} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const Middle = ({style, ...props}: ViewProps) => (
const Right = ({style, ...props}: ViewProps) => <View style={[style, {padding: 4}]} {...props} />
const Amount = ({wallet, transaction}: {wallet: YoroiWallet; transaction: TransactionInfo}) => {
const {styles} = useStyles()
const {isPrivacyOff} = usePrivacyMode()
const {isPrivacyOff, privacyPlaceholder} = usePrivacyMode()
const amountAsMT = MultiToken.fromArray(transaction.amount)
const amount: BigNumber = amountAsMT.getDefault()
const fee = transaction.fee ? transaction.fee[0] : null
Expand All @@ -123,9 +123,11 @@ const Amount = ({wallet, transaction}: {wallet: YoroiWallet; transaction: Transa
return (
<View style={styles.amount} testID="transactionAmount">
<Text style={style} secondary={transaction.assurance === 'PENDING'}>
<Text>{isPrivacyOff ? '*' : formatTokenInteger(asQuantity(amount), wallet.primaryToken)}</Text>
<Text>{isPrivacyOff && formatTokenInteger(asQuantity(amount), wallet.primaryToken)}</Text>

<Text small>{isPrivacyOff ? '.******' : formatTokenFractional(asQuantity(amount), wallet.primaryToken)}</Text>
<Text small>
{isPrivacyOff ? formatTokenFractional(asQuantity(amount), wallet.primaryToken) : privacyPlaceholder}
</Text>
</Text>

<Text style={style}>{`${utfSymbols.NBSP}${wallet.primaryTokenInfo.symbol}`}</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,74 @@
"defaultMessage": "!!!Fee",
"file": "src/TxHistory/TxHistoryList/TxHistoryListItem.tsx",
"start": {
"line": 174,
"line": 176,
"column": 7,
"index": 6087
"index": 6131
},
"end": {
"line": 177,
"line": 179,
"column": 3,
"index": 6176
"index": 6220
}
},
{
"id": "components.txhistory.txhistorylistitem.transactionTypeSent",
"defaultMessage": "!!!ADA sent",
"file": "src/TxHistory/TxHistoryList/TxHistoryListItem.tsx",
"start": {
"line": 178,
"line": 180,
"column": 23,
"index": 6201
"index": 6245
},
"end": {
"line": 181,
"line": 183,
"column": 3,
"index": 6311
"index": 6355
}
},
{
"id": "components.txhistory.txhistorylistitem.transactionTypeReceived",
"defaultMessage": "!!!ADA received",
"file": "src/TxHistory/TxHistoryList/TxHistoryListItem.tsx",
"start": {
"line": 182,
"line": 184,
"column": 27,
"index": 6340
"index": 6384
},
"end": {
"line": 185,
"line": 187,
"column": 3,
"index": 6458
"index": 6502
}
},
{
"id": "components.txhistory.txhistorylistitem.transactionTypeSelf",
"defaultMessage": "!!!Intrawallet",
"file": "src/TxHistory/TxHistoryList/TxHistoryListItem.tsx",
"start": {
"line": 186,
"line": 188,
"column": 23,
"index": 6483
"index": 6527
},
"end": {
"line": 189,
"line": 191,
"column": 3,
"index": 6596
"index": 6640
}
},
{
"id": "components.txhistory.txhistorylistitem.transactionTypeMulti",
"defaultMessage": "!!!Multiparty",
"file": "src/TxHistory/TxHistoryList/TxHistoryListItem.tsx",
"start": {
"line": 190,
"line": 192,
"column": 24,
"index": 6622
"index": 6666
},
"end": {
"line": 193,
"line": 195,
"column": 3,
"index": 6735
"index": 6779
}
},
{
Expand All @@ -80,14 +80,14 @@
"defaultMessage": "!!!{cnt} assets",
"file": "src/TxHistory/TxHistoryList/TxHistoryListItem.tsx",
"start": {
"line": 194,
"line": 196,
"column": 10,
"index": 6747
"index": 6791
},
"end": {
"line": 198,
"line": 200,
"column": 3,
"index": 6899
"index": 6943
}
}
]

0 comments on commit feacdef

Please sign in to comment.