-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
frontend: move conversion amount to its own component
Moving to components so that ConversionAmount can be re-used in other components.
- Loading branch information
1 parent
537e4b4
commit d691923
Showing
6 changed files
with
99 additions
and
76 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
frontends/web/src/components/amount/conversion-amount.module.css
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,23 @@ | ||
.txConversionAmount { | ||
font-variant: tabular-nums; | ||
} | ||
|
||
.txPrefix, | ||
.txUnit { | ||
color: var(--color-secondary); | ||
font-size: 14px; | ||
line-height: 1.285714; | ||
} | ||
|
||
.txConversionAmount .txUnit { | ||
font-size: 12px; | ||
} | ||
|
||
.txSmallInlineIcon img { | ||
max-height: 15px; | ||
max-width: 15px; | ||
vertical-align: text-bottom; | ||
} | ||
.txConversionAmount .txSmallInlineIcon { | ||
padding-right: var(--space-eight); | ||
} |
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,73 @@ | ||
/** | ||
* Copyright 2025 Shift Crypto AG | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { useContext } from 'react'; | ||
import type { IAmount, TTransactionType } from '@/api/account'; | ||
import { RatesContext } from '@/contexts/RatesContext'; | ||
import { Arrow } from '@/components/transactions/components/arrows'; | ||
import { Amount } from '@/components/amount/amount'; | ||
import { getTxSign } from '@/utils/transaction'; | ||
import styles from './conversion-amount.module.css'; | ||
|
||
type TConversionAmountProps = { | ||
amount: IAmount; | ||
type: TTransactionType; | ||
} | ||
|
||
const btcUnits: Readonly<string[]> = ['BTC', 'TBTC', 'sat', 'tsat']; | ||
|
||
/** | ||
* Renders a formattted conversion amount optionally with send-to-self icon or estimate symbol | ||
*/ | ||
export const ConversionAmount = ({ | ||
amount, | ||
type, | ||
}: TConversionAmountProps) => { | ||
const { defaultCurrency } = useContext(RatesContext); | ||
const conversion = amount?.conversions && amount?.conversions[defaultCurrency]; | ||
const sign = getTxSign(type); | ||
const estimatedPrefix = '\u2248'; // ≈ | ||
const sendToSelf = type === 'send_to_self'; | ||
const conversionUnit = sendToSelf ? amount.unit : defaultCurrency; | ||
|
||
// we skip the estimated conversion prefix when the Tx is send to self, or both coin and conversion are in BTC units. | ||
const skipEstimatedPrefix = sendToSelf || (btcUnits.includes(conversionUnit) && btcUnits.includes(amount.unit)); | ||
|
||
return ( | ||
<span className={styles.txConversionAmount}> | ||
{sendToSelf && ( | ||
<span className={styles.txSmallInlineIcon}> | ||
<Arrow type="send_to_self" /> | ||
</span> | ||
)} | ||
{amount.estimated && !skipEstimatedPrefix && ( | ||
<span className={styles.txPrefix}> | ||
{estimatedPrefix} | ||
{' '} | ||
</span> | ||
)} | ||
{conversion && !sendToSelf ? sign : null} | ||
<Amount | ||
amount={sendToSelf ? amount.amount : conversion || ''} | ||
unit={conversionUnit} | ||
/> | ||
<span className={styles.txUnit}> | ||
{' '} | ||
{conversionUnit} | ||
</span> | ||
</span> | ||
); | ||
}; |
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
File renamed without changes.