Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DDW-814] Introduce configurable replacer pattern
- Loading branch information
1 parent
97b0891
commit c9c19b0
Showing
14 changed files
with
137 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
source/renderer/app/features/discreet-mode/replacers/defaultReplacer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// @flow | ||
export function defaultReplacer() { | ||
return (isDiscreetMode, symbol: string, value: any) => { | ||
return isDiscreetMode ? symbol : value; | ||
}; | ||
} |
26 changes: 26 additions & 0 deletions
26
source/renderer/app/features/discreet-mode/replacers/discreetWalletAmount.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// @flow | ||
import BigNumber from 'bignumber.js'; | ||
import { formattedWalletAmount } from '../../../utils/formatters'; | ||
import { DiscreetValueReplacer } from '../types'; | ||
|
||
export type DiscreetWalletAmountProps = { | ||
amount: BigNumber, | ||
withCurrency?: boolean, | ||
long?: boolean, | ||
}; | ||
|
||
export const discreetWalletAmount: DiscreetValueReplacer = ({ | ||
amount, | ||
withCurrency = true, | ||
long = true, | ||
}: DiscreetWalletAmountProps) => { | ||
return (isDiscreetMode, replacement) => { | ||
if (!isDiscreetMode) { | ||
return formattedWalletAmount(amount, withCurrency, long); | ||
} | ||
if (!withCurrency) { | ||
return replacement; | ||
} | ||
return `${replacement} ADA`; | ||
}; | ||
}; |
30 changes: 30 additions & 0 deletions
30
source/renderer/app/features/discreet-mode/replacers/discreetWalletTokenAmount.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// @flow | ||
import BigNumber from 'bignumber.js'; | ||
import type { AssetMetadata } from '../../../api/assets/types'; | ||
import { formattedTokenWalletAmount } from '../../../utils/formatters'; | ||
import { DiscreetValueReplacer } from '../types'; | ||
|
||
export type DiscreetWalletTokenAmountProps = { | ||
amount: BigNumber, | ||
metadata?: ?AssetMetadata, | ||
decimals: ?number, | ||
isShort?: boolean, | ||
}; | ||
|
||
export const discreetWalletTokenAmount: DiscreetValueReplacer = ({ | ||
amount, | ||
metadata, | ||
decimals, | ||
isShort, | ||
}: DiscreetWalletTokenAmountProps) => { | ||
return (isDiscreetMode, replacement) => { | ||
if (!isDiscreetMode) { | ||
return formattedTokenWalletAmount(amount, metadata, decimals, isShort); | ||
} | ||
const { ticker } = metadata || {}; | ||
if (!ticker) { | ||
return replacement; | ||
} | ||
return `${replacement} ${ticker}`; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// @flow | ||
|
||
export type DiscreetValueReplacer = () => ( | ||
isDiscreetMode: boolean, | ||
symbol: string, | ||
value: any | ||
) => string; |
23 changes: 8 additions & 15 deletions
23
source/renderer/app/features/discreet-mode/ui/DiscreetTokenWalletAmount.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,14 @@ | ||
// @flow | ||
import React from 'react'; | ||
import BigNumber from 'bignumber.js'; | ||
import { observer } from 'mobx-react'; | ||
import type { AssetMetadata } from '../../../api/assets/types'; | ||
import { useDiscreetModeFeature } from '../context'; | ||
|
||
type Props = { | ||
amount: BigNumber, | ||
metadata?: ?AssetMetadata, | ||
decimals: ?number, | ||
isShort?: boolean, | ||
}; | ||
|
||
function DiscreetTokenWalletAmount(props: Props) { | ||
const feature = useDiscreetModeFeature(); | ||
|
||
return <>{feature.hideOrShowTokenWalletAmount(props)}</>; | ||
import { | ||
discreetWalletTokenAmount, | ||
DiscreetWalletTokenAmountProps, | ||
} from '../replacers/discreetWalletTokenAmount'; | ||
import DiscreetValue from './DiscreetValue'; | ||
|
||
function DiscreetTokenWalletAmount(props: DiscreetWalletTokenAmountProps) { | ||
return <DiscreetValue replacer={discreetWalletTokenAmount(props)} />; | ||
} | ||
|
||
export default observer(DiscreetTokenWalletAmount); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 8 additions & 16 deletions
24
source/renderer/app/features/discreet-mode/ui/DiscreetWalletAmount.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,11 @@ | ||
// @flow | ||
import React from 'react'; | ||
import BigNumber from 'bignumber.js'; | ||
import { observer } from 'mobx-react'; | ||
import { useDiscreetModeFeature } from '../context'; | ||
|
||
type Props = { | ||
amount: BigNumber, | ||
withCurrency?: boolean, | ||
long?: boolean, | ||
}; | ||
|
||
function DiscreetWalletAmount(props: Props) { | ||
const feature = useDiscreetModeFeature(); | ||
|
||
return <>{feature.hideOrShowWalletAmount(props)}</>; | ||
import { | ||
discreetWalletAmount, | ||
DiscreetWalletAmountProps, | ||
} from '../replacers/discreetWalletAmount'; | ||
import DiscreetValue from './DiscreetValue'; | ||
|
||
export default function DiscreetWalletAmount(props: DiscreetWalletAmountProps) { | ||
return <DiscreetValue replacer={discreetWalletAmount(props)} />; | ||
} | ||
|
||
export default observer(DiscreetWalletAmount); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters