Skip to content

Commit cd52c58

Browse files
authored
Merge pull request xch-dev#552 from dkackman/refine-offer-page
Display xch ticker in xch amount
2 parents 419bdf2 + 5921dbc commit cd52c58

File tree

5 files changed

+45
-35
lines changed

5 files changed

+45
-35
lines changed

src/components/dialogs/MakeOfferConfirmationDialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@ function AssetDisplay({
182182
<div className='space-y-2'>
183183
{hasXch && (
184184
<div>
185-
<h4 className='font-semibold'>XCH</h4>
185+
<h4 className='font-semibold'>{xchToken?.ticker ?? 'XCH'}</h4>
186186
{loadingXch ? (
187187
<p className='text-sm text-muted-foreground'>
188-
<Trans>Loading XCH details...</Trans>
188+
<Trans>Loading {xchToken?.ticker ?? 'XCH'} details...</Trans>
189189
</p>
190190
) : (
191191
<div className='flex items-center gap-2'>

src/components/selectors/AssetSelector.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from '@/components/ui/tooltip';
1515
import useOfferStateWithDefault from '@/hooks/useOfferStateWithDefault';
1616
import { usePrices } from '@/hooks/usePrices';
17+
import { useWalletState } from '@/state';
1718
import { t } from '@lingui/core/macro';
1819
import { Trans } from '@lingui/react/macro';
1920
import {
@@ -48,6 +49,7 @@ export function AssetSelector({
4849
const [includeAmount, setIncludeAmount] = useState(!!assets.xch);
4950
const [ownedTokens, setOwnedTokens] = useState<TokenRecord[]>([]);
5051
const { getCatAskPriceInXch } = usePrices();
52+
const walletState = useWalletState();
5153

5254
// Notify parent of XCH state changes
5355
useEffect(() => {
@@ -78,7 +80,7 @@ export function AssetSelector({
7880
onClick={() => setIncludeAmount(true)}
7981
>
8082
<PlusIcon className='mr-0.5 h-3 w-3' />
81-
XCH
83+
{walletState.sync.unit.ticker}
8284
</Button>
8385
<Button
8486
variant='outline'
@@ -108,14 +110,17 @@ export function AssetSelector({
108110

109111
{includeAmount && (
110112
<div className='mt-4 flex flex-col space-y-1.5'>
111-
<Label htmlFor={`${prefix}-amount`}>XCH</Label>
113+
<Label htmlFor={`${prefix}-amount`}>
114+
{walletState.sync.unit.ticker}
115+
</Label>
112116
<div className='flex'>
113117
<TokenAmountInput
114118
id={`${prefix}-amount`}
115119
type='text'
116120
className='rounded-r-none z-10'
117121
placeholder={t`Enter amount`}
118122
value={assets.xch}
123+
ticker='xch'
119124
onValueChange={(values) => {
120125
setAssets({
121126
...assets,
@@ -146,7 +151,10 @@ export function AssetSelector({
146151
</Button>
147152
</TooltipTrigger>
148153
<TooltipContent>
149-
<Trans>Convert to XCH at current asking price</Trans>
154+
<Trans>
155+
Convert to {walletState.sync.unit.ticker} at current
156+
asking price
157+
</Trans>
150158
</TooltipContent>
151159
</Tooltip>
152160
</TooltipProvider>

src/components/ui/masked-input.tsx

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,36 @@ function isLocaleNumber(stringNumber: string, locale?: string): boolean {
6060
MaskedInput.displayName = 'MaskedInput';
6161

6262
// Extended Masked Input for XCH inputs
63-
interface XchInputProps extends MaskedInputProps {
63+
interface TokenInputProps extends MaskedInputProps {
6464
decimals?: number;
65+
ticker?: string | null;
6566
}
6667

67-
const TokenAmountInput = React.forwardRef<HTMLInputElement, XchInputProps>(
68-
({ decimals = 24, ...props }, ref) => (
69-
<MaskedInput
70-
placeholder='0.00'
71-
{...props}
72-
type='text'
73-
inputRef={ref}
74-
decimalScale={decimals}
75-
allowLeadingZeros={true}
76-
allowNegative={false}
77-
/>
78-
),
68+
const TokenAmountInput = React.forwardRef<HTMLInputElement, TokenInputProps>(
69+
({ decimals = 24, ticker = null, ...props }, ref) => {
70+
const walletState = useWalletState();
71+
72+
return (
73+
<div className='relative'>
74+
<MaskedInput
75+
placeholder='0.00'
76+
{...props}
77+
type='text'
78+
inputRef={ref}
79+
decimalScale={decimals}
80+
allowLeadingZeros={true}
81+
allowNegative={false}
82+
/>
83+
{ticker && (
84+
<div className='pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3'>
85+
<span className='text-gray-500 text-sm'>
86+
{ticker === 'xch' ? walletState.sync.unit.ticker : ticker}
87+
</span>
88+
</div>
89+
)}
90+
</div>
91+
);
92+
},
7993
);
8094

8195
TokenAmountInput.displayName = 'TokenAmountInput';
@@ -112,7 +126,7 @@ const IntegerInput = React.forwardRef<HTMLInputElement, IntegerInputProps>(
112126
IntegerInput.displayName = 'IntegerInput';
113127

114128
// Fee input that uses the default fee value as initial value
115-
interface FeeAmountInputProps extends Omit<XchInputProps, 'value'> {
129+
interface FeeAmountInputProps extends Omit<TokenInputProps, 'value'> {
116130
value?: string;
117131
className?: string;
118132
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
@@ -125,7 +139,6 @@ interface FeeAmountInputProps extends Omit<XchInputProps, 'value'> {
125139
const FeeAmountInput = React.forwardRef<HTMLInputElement, FeeAmountInputProps>(
126140
({ value, className, onChange, onValueChange, ...props }, ref) => {
127141
const { fee: defaultFee } = useDefaultFee();
128-
const walletState = useWalletState();
129142
const hasSetInitialValue = React.useRef(false);
130143

131144
// Set initial value when component mounts
@@ -154,12 +167,8 @@ const FeeAmountInput = React.forwardRef<HTMLInputElement, FeeAmountInputProps>(
154167
placeholder={t`Enter network fee`}
155168
aria-label={t`Network fee amount`}
156169
className={`pr-12 ${className || ''}`}
170+
ticker='xch'
157171
/>
158-
<div className='pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3'>
159-
<span className='text-gray-500 text-sm' id='price-currency'>
160-
{walletState.sync.unit.ticker}
161-
</span>
162-
</div>
163172
</div>
164173
);
165174
},

src/pages/MakeOffer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ export function MakeOffer() {
8080
if (hasOfferedXchAdded && !hasOfferedXchValid) {
8181
addError({
8282
kind: 'invalid',
83-
reason: t`Offered XCH amount must be a positive number.`,
83+
reason: t`Offered ${walletState.sync.unit.ticker} amount must be a positive number.`,
8484
});
8585
return;
8686
}
8787

8888
if (hasRequestedXchAdded && !hasRequestedXchValid) {
8989
addError({
9090
kind: 'invalid',
91-
reason: t`Requested XCH amount must be a positive number.`,
91+
reason: t`Requested ${walletState.sync.unit.ticker} amount must be a positive number.`,
9292
});
9393
return;
9494
}

src/pages/Send.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ export default function Send() {
299299
<div className='relative flex'>
300300
<TokenAmountInput
301301
{...field}
302+
ticker={asset?.ticker}
302303
className='pr-12 rounded-r-none z-10'
303304
/>
304305
<TooltipProvider>
@@ -331,14 +332,6 @@ export default function Send() {
331332
</TooltipContent>
332333
</Tooltip>
333334
</TooltipProvider>
334-
<div className='pointer-events-none absolute inset-y-0 right-12 flex items-center pr-3'>
335-
<span
336-
className='text-gray-500 text-sm'
337-
id='price-currency'
338-
>
339-
{asset?.ticker}
340-
</span>
341-
</div>
342335
</div>
343336
</FormControl>
344337
<FormMessage />

0 commit comments

Comments
 (0)