-
Notifications
You must be signed in to change notification settings - Fork 144
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
a87a438
commit df77eb9
Showing
23 changed files
with
395 additions
and
110 deletions.
There are no files selected for viewing
File renamed without changes
25 changes: 25 additions & 0 deletions
25
src/app/components/crypto-assets/choose-crypto-asset/choose-asset-container.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,25 @@ | ||
import { Flex } from 'leather-styles/jsx'; | ||
|
||
import { HasChildren } from '@app/common/has-children'; | ||
import { whenPageMode } from '@app/common/utils'; | ||
|
||
export function ChooseAssetContainer({ children }: HasChildren) { | ||
return whenPageMode({ | ||
full: ( | ||
<Flex | ||
borderRadius={['unset', '16px']} | ||
height="fit-content" | ||
maxWidth={['100%', 'centeredPageFullWidth']} | ||
minWidth={['100%', 'centeredPageFullWidth']} | ||
background="accent.background-primary" | ||
> | ||
{children} | ||
</Flex> | ||
), | ||
popup: ( | ||
<Flex background="accent.background-primary" width="100%"> | ||
{children} | ||
</Flex> | ||
), | ||
}); | ||
} |
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
81 changes: 81 additions & 0 deletions
81
src/app/pages/fund/choose-asset-to-fund/choose-asset-to-fund.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,81 @@ | ||
import { useCallback, useMemo } from 'react'; | ||
import { Outlet, useNavigate } from 'react-router-dom'; | ||
|
||
import { AllTransferableCryptoAssetBalances } from '@shared/models/crypto-asset-balance.model'; | ||
import { RouteUrls } from '@shared/route-urls'; | ||
|
||
import { useStxBalance } from '@app/common/hooks/balance/stx/use-stx-balance'; | ||
import { useRouteHeader } from '@app/common/hooks/use-route-header'; | ||
import { useWalletType } from '@app/common/use-wallet-type'; | ||
import { ChooseAssetContainer } from '@app/components/crypto-assets/choose-crypto-asset/choose-asset-container'; | ||
import { ChooseCryptoAssetLayout } from '@app/components/crypto-assets/choose-crypto-asset/choose-crypto-asset.layout'; | ||
import { CryptoAssetList } from '@app/components/crypto-assets/choose-crypto-asset/crypto-asset-list'; | ||
import { ModalHeader } from '@app/components/modal-header'; | ||
import { useNativeSegwitBalance } from '@app/query/bitcoin/balance/btc-native-segwit-balance.hooks'; | ||
import { createStacksCryptoCurrencyAssetTypeWrapper } from '@app/query/stacks/balance/stacks-ft-balances.utils'; | ||
import { useCurrentAccountNativeSegwitSigner } from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks'; | ||
import { useCheckLedgerBlockchainAvailable } from '@app/store/accounts/blockchain/utils'; | ||
|
||
function useBtcCryptoCurrencyAssetBalance() { | ||
const currentBtcSigner = useCurrentAccountNativeSegwitSigner(); | ||
if (!currentBtcSigner?.(0).address) throw new Error('No bitcoin address'); | ||
|
||
return useNativeSegwitBalance(currentBtcSigner?.(0).address); | ||
} | ||
|
||
function useStxCryptoCurrencyAssetBalance() { | ||
const { availableBalance: availableStxBalance } = useStxBalance(); | ||
return createStacksCryptoCurrencyAssetTypeWrapper(availableStxBalance.amount); | ||
} | ||
|
||
export function ChooseCryptoAssetToFund() { | ||
const btcCryptoCurrencyAssetBalance = useBtcCryptoCurrencyAssetBalance(); | ||
const stxCryptoCurrencyAssetBalance = useStxCryptoCurrencyAssetBalance(); | ||
|
||
const cryptoCurrencyAssetBalances = useMemo( | ||
() => [btcCryptoCurrencyAssetBalance, stxCryptoCurrencyAssetBalance], | ||
[btcCryptoCurrencyAssetBalance, stxCryptoCurrencyAssetBalance] | ||
); | ||
|
||
const { whenWallet } = useWalletType(); | ||
const navigate = useNavigate(); | ||
|
||
const checkBlockchainAvailable = useCheckLedgerBlockchainAvailable(); | ||
|
||
const filteredCryptoAssetBalances = useMemo( | ||
() => | ||
cryptoCurrencyAssetBalances.filter(assetBalance => | ||
whenWallet({ | ||
ledger: checkBlockchainAvailable(assetBalance.blockchain), | ||
software: true, | ||
}) | ||
), | ||
[cryptoCurrencyAssetBalances, checkBlockchainAvailable, whenWallet] | ||
); | ||
|
||
useRouteHeader(<ModalHeader hideActions onGoBack={() => navigate(RouteUrls.Home)} title=" " />); | ||
|
||
const navigateToSendForm = useCallback( | ||
(cryptoAssetBalance: AllTransferableCryptoAssetBalances) => { | ||
const { asset } = cryptoAssetBalance; | ||
|
||
const symbol = asset.symbol === '' ? asset.contractAssetName : asset.symbol; | ||
navigate(RouteUrls.Fund.replace(':currency', symbol.toUpperCase())); | ||
}, | ||
[navigate] | ||
); | ||
|
||
return ( | ||
<> | ||
<ChooseAssetContainer> | ||
<ChooseCryptoAssetLayout title="choose asset to fund"> | ||
<CryptoAssetList | ||
onItemClick={navigateToSendForm} | ||
cryptoAssetBalances={filteredCryptoAssetBalances} | ||
/> | ||
</ChooseCryptoAssetLayout> | ||
</ChooseAssetContainer> | ||
<Outlet /> | ||
</> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import BitcoinIcon from '@assets/images/btc-icon.png'; | ||
import ReceiveFundsEllipses from '@assets/images/fund/receive-funds-ellipses.png'; | ||
import StacksIcon from '@assets/images/fund/stacks-icon.png'; | ||
import { Box } from 'leather-styles/jsx'; | ||
|
||
export function StacksIconComponent() { | ||
return ( | ||
<> | ||
<Box> | ||
<img src={StacksIcon} width="40px" /> | ||
</Box> | ||
<Box> | ||
<img src={ReceiveFundsEllipses} width="24px" /> | ||
</Box> | ||
</> | ||
); | ||
} | ||
|
||
export function BitcoinIconComponent() { | ||
return ( | ||
<> | ||
<Box> | ||
<img src={BitcoinIcon} width="40px" /> | ||
</Box> | ||
<Box> | ||
<img src={ReceiveFundsEllipses} width="24px" /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react'; | ||
|
||
import QRCodeIcon from '@assets/images/fund/qr-code-icon.png'; | ||
import { FundPageSelectors } from '@tests/selectors/fund.selectors'; | ||
|
||
import { CryptoCurrencies } from '@shared/models/currencies.model'; | ||
|
||
import { FundAccountTile } from './fund-account-tile'; | ||
import { BitcoinIconComponent, StacksIconComponent } from './icon-components'; | ||
|
||
interface CryptoDescription { | ||
title: string; | ||
IconComponent(): React.JSX.Element; | ||
} | ||
|
||
const cryptoDescriptions: Record<CryptoCurrencies, CryptoDescription> = { | ||
STX: { | ||
title: 'Receive STX from a friend or deposit from a separate wallet', | ||
IconComponent: StacksIconComponent, | ||
}, | ||
BTC: { | ||
title: 'Receive BTC from a friend or deposit from a separate wallet', | ||
IconComponent: BitcoinIconComponent, | ||
}, | ||
}; | ||
interface ReceiveStxItemProps { | ||
onReceive(): void; | ||
symbol: CryptoCurrencies; | ||
} | ||
export function ReceiveFundsItem({ onReceive, symbol }: ReceiveStxItemProps) { | ||
return ( | ||
<FundAccountTile | ||
description={cryptoDescriptions[symbol].title} | ||
icon={QRCodeIcon} | ||
onClickTile={onReceive} | ||
ReceiveStxIcon={cryptoDescriptions[symbol].IconComponent} | ||
testId={FundPageSelectors.BtnReceiveStx} | ||
/> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.