forked from leather-io/extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afe15f4
commit 485dbcd
Showing
30 changed files
with
504 additions
and
141 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
35 changes: 35 additions & 0 deletions
35
src/app/pages/send/ordinal-inscription/send-inscription-set-fee.tsx
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,35 @@ | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
// import get from 'lodash.get'; | ||
// import { RouteUrls } from '@shared/route-urls'; | ||
import { BaseDrawer } from '@app/components/drawer/base-drawer'; | ||
|
||
// import { BitcoinSetFee } from '../send-crypto-asset-form/family/bitcoin/components/bitcoin-set-fee'; | ||
// import { useInscriptionSendState } from './send-inscription-container'; | ||
|
||
// function useSendInscriptionSetFeeState() { | ||
// const location = useLocation(); | ||
// return { | ||
// tx: get(location.state, 'tx') as string, | ||
// recipient: get(location.state, 'recipient', '') as string, | ||
// }; | ||
// } | ||
|
||
export function SendInscriptionSetFee() { | ||
const navigate = useNavigate(); | ||
// const { tx, recipient } = useSendInscriptionSetFeeState(); | ||
// const { inscription, utxo } = useInscriptionSendState(); | ||
|
||
// function previewTransaction(feeRate: number, feeValue: number, time: string) { | ||
// feeRate; | ||
// navigate(RouteUrls.SendOrdinalInscriptionReview, { | ||
// state: { fee: feeValue, inscription, utxo, recipient, tx, arrivesIn: time }, | ||
// }); | ||
// } | ||
|
||
return ( | ||
<BaseDrawer title="Choose fee" isShowing enableGoBack onClose={() => navigate(-1)}> | ||
{/* <BitcoinSetFee onChooseFee={previewTransaction} recipient={recipient} amount={}/>; */} | ||
</BaseDrawer> | ||
); | ||
} |
36 changes: 36 additions & 0 deletions
36
src/app/pages/send/send-crypto-asset-form/components/fees-card.tsx
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,36 @@ | ||
import { Box, Flex, Text, color, transition } from '@stacks/ui'; | ||
import { SharedComponentsSelectors } from '@tests/selectors/shared-component.selectors'; | ||
|
||
interface FeesCardProps { | ||
feeType: string; | ||
feeAmount: string; | ||
feeFiatValue: string; | ||
arrivesIn: string; | ||
onClick: () => void; | ||
} | ||
export function FeesCard({ feeType, feeAmount, feeFiatValue, arrivesIn, ...props }: FeesCardProps) { | ||
return ( | ||
<Box | ||
as="button" | ||
border="1px solid" | ||
borderColor={color('border')} | ||
borderRadius="16px" | ||
boxShadow="0px 1px 2px rgba(0, 0, 0, 0.04)" | ||
transition={transition} | ||
padding="extra-loose" | ||
width="100%" | ||
_hover={{ background: '#F9F9FA' }} | ||
data-testid={SharedComponentsSelectors.FeeCard} | ||
{...props} | ||
> | ||
<Flex justifyContent="space-between" mb="tight" fontWeight={500}> | ||
<Text>{feeType}</Text> | ||
<Text data-testid={SharedComponentsSelectors.FeeCardFeeValue}>{feeAmount}</Text> | ||
</Flex> | ||
<Flex justifyContent="space-between" color="#74777D"> | ||
<Text>{arrivesIn}</Text> | ||
<Text>{feeFiatValue}</Text> | ||
</Flex> | ||
</Box> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ export function PreviewButton(props: ButtonProps) { | |
width="100%" | ||
{...props} | ||
> | ||
Preview | ||
Continue | ||
</Button> | ||
); | ||
} |
36 changes: 36 additions & 0 deletions
36
src/app/pages/send/send-crypto-asset-form/family/bitcoin/components/bitcoin-set-fee.tsx
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,36 @@ | ||
import { Stack, Text } from '@stacks/ui'; | ||
|
||
import { FeesCard } from '../../../components/fees-card'; | ||
import { useBitcoinSetFees } from './use-bitcoin-set-fees'; | ||
|
||
interface BitcoinSetFeeProps { | ||
onChooseFee(feeRate: number, feeValue: number, time: string): Promise<void> | void; | ||
recipient: string; | ||
amount: number; | ||
} | ||
|
||
export function BitcoinSetFee({ onChooseFee, recipient, amount }: BitcoinSetFeeProps) { | ||
const { feesList } = useBitcoinSetFees({ recipient, amount }); | ||
|
||
return ( | ||
<Stack p="extra-loose" width="100%" spacing="extra-loose" alignItems="center"> | ||
<Stack width="100%" spacing="base"> | ||
{feesList.map(({ label, value, btcValue, fiatValue, time, feeRate }) => ( | ||
<FeesCard | ||
key={label} | ||
feeType={label} | ||
feeAmount={btcValue} | ||
feeFiatValue={fiatValue} | ||
arrivesIn={time} | ||
onClick={() => onChooseFee(feeRate, value, time)} | ||
/> | ||
))} | ||
</Stack> | ||
|
||
<Text fontSize="14px" color="#74777D" textAlign="center"> | ||
Fees are deducted from your balance, | ||
<br /> it won't affect your sending amount. | ||
</Text> | ||
</Stack> | ||
); | ||
} |
90 changes: 90 additions & 0 deletions
90
src/app/pages/send/send-crypto-asset-form/family/bitcoin/components/use-bitcoin-set-fees.ts
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,90 @@ | ||
import { useMemo } from 'react'; | ||
|
||
import { createMoney } from '@shared/models/money.model'; | ||
|
||
import { baseCurrencyAmountInQuote } from '@app/common/money/calculate-money'; | ||
import { formatMoneyPadded, i18nFormatCurrency } from '@app/common/money/format-money'; | ||
import { btcToSat } from '@app/common/money/unit-conversion'; | ||
import { determineUtxosForSpend } from '@app/common/transactions/bitcoin/coinselect/local-coin-selection'; | ||
import { useGetUtxosByAddressQuery } from '@app/query/bitcoin/address/utxos-by-address.query'; | ||
import { BtcFeeType, btcTxTimeMap } from '@app/query/bitcoin/bitcoin-client'; | ||
import { useBitcoinFeeRate } from '@app/query/bitcoin/fees/fee-estimates.hooks'; | ||
import { useCryptoCurrencyMarketData } from '@app/query/common/market-data/market-data.hooks'; | ||
import { useCurrentBtcNativeSegwitAccountAddressIndexZero } from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks'; | ||
|
||
interface UseBitcoinSetFeesArgs { | ||
recipient: string; | ||
amount: number; | ||
} | ||
|
||
export function useBitcoinSetFees({ recipient, amount }: UseBitcoinSetFeesArgs) { | ||
const currentAccountBtcAddress = useCurrentBtcNativeSegwitAccountAddressIndexZero(); | ||
const { data: utxos } = useGetUtxosByAddressQuery(currentAccountBtcAddress); | ||
|
||
const btcMarketData = useCryptoCurrencyMarketData('BTC'); | ||
const { data: feeRate } = useBitcoinFeeRate(); | ||
|
||
const feesList = useMemo(() => { | ||
function getFiatFeeValue(fee: number) { | ||
return `~ ${i18nFormatCurrency( | ||
baseCurrencyAmountInQuote(createMoney(Math.ceil(fee), 'BTC'), btcMarketData) | ||
)}`; | ||
} | ||
|
||
if (!feeRate || !utxos) return []; | ||
|
||
const satAmount = btcToSat(amount).toNumber(); | ||
const { fee: highFeeValue } = determineUtxosForSpend({ | ||
utxos, | ||
recipient, | ||
amount: satAmount, | ||
feeRate: feeRate.fastestFee, | ||
}); | ||
|
||
const { fee: standartFeeValue } = determineUtxosForSpend({ | ||
utxos, | ||
recipient, | ||
amount: satAmount, | ||
feeRate: feeRate.halfHourFee, | ||
}); | ||
|
||
const { fee: lowFeeValue } = determineUtxosForSpend({ | ||
utxos, | ||
recipient, | ||
amount: satAmount, | ||
feeRate: feeRate.economyFee, | ||
}); | ||
|
||
return [ | ||
{ | ||
label: BtcFeeType.High, | ||
value: highFeeValue, | ||
btcValue: formatMoneyPadded(createMoney(highFeeValue, 'BTC')), | ||
time: btcTxTimeMap.fastestFee, | ||
fiatValue: getFiatFeeValue(highFeeValue), | ||
feeRate: feeRate.fastestFee, | ||
}, | ||
|
||
{ | ||
label: BtcFeeType.Standard, | ||
value: standartFeeValue, | ||
btcValue: formatMoneyPadded(createMoney(standartFeeValue, 'BTC')), | ||
time: btcTxTimeMap.halfHourFee, | ||
fiatValue: getFiatFeeValue(standartFeeValue), | ||
feeRate: feeRate.halfHourFee, | ||
}, | ||
{ | ||
label: BtcFeeType.Low, | ||
value: lowFeeValue, | ||
btcValue: formatMoneyPadded(createMoney(lowFeeValue, 'BTC')), | ||
time: btcTxTimeMap.economyFee, | ||
fiatValue: getFiatFeeValue(lowFeeValue), | ||
feeRate: feeRate.economyFee, | ||
}, | ||
]; | ||
}, [feeRate, btcMarketData, utxos, recipient, amount]); | ||
|
||
return { | ||
feesList, | ||
}; | ||
} |
Oops, something went wrong.