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.
feat: add brc-20 send flow, closes leather-io#3669
- Loading branch information
1 parent
3805c77
commit f12322b
Showing
34 changed files
with
1,204 additions
and
92 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
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,12 @@ | ||
export function StatusPending() { | ||
return ( | ||
<div | ||
style={{ | ||
width: '8px', | ||
height: '8px', | ||
borderRadius: '50%', | ||
backgroundColor: '#F59300', | ||
}} | ||
/> | ||
); | ||
} |
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,12 @@ | ||
export function StatusReady() { | ||
return ( | ||
<div | ||
style={{ | ||
width: '8px', | ||
height: '8px', | ||
borderRadius: '50%', | ||
backgroundColor: '#23A978', | ||
}} | ||
/> | ||
); | ||
} |
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
138 changes: 138 additions & 0 deletions
138
src/app/features/pending-brc-20-transfers/pending-brc-20-transfers.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,138 @@ | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
import { Box, Flex, Stack, Text } from '@stacks/ui'; | ||
|
||
import { RouteUrls } from '@shared/route-urls'; | ||
import { noop } from '@shared/utils'; | ||
|
||
import { CaptionDotSeparator } from '@app/components/caption-dot-separator'; | ||
import { usePressable } from '@app/components/item-hover'; | ||
import { Flag } from '@app/components/layout/flag'; | ||
import { StatusPending } from '@app/components/status-pending'; | ||
import { StatusReady } from '@app/components/status-ready'; | ||
import { Tooltip } from '@app/components/tooltip'; | ||
import { Caption } from '@app/components/typography'; | ||
import { useCheckOrderStatuses } from '@app/query/bitcoin/ordinals/brc20/use-check-order-status'; | ||
import { convertInscriptionToSupportedInscriptionType } from '@app/query/bitcoin/ordinals/inscription.hooks'; | ||
import { fetchInscripionById } from '@app/query/bitcoin/ordinals/use-inscription-by-id'; | ||
import { useOrdinalsbotClient } from '@app/query/bitcoin/ordinalsbot-client'; | ||
import { | ||
OrdinalsbotInscriptionStatus, | ||
PendingBrc20Transfer, | ||
usePendingBrc20Transfers, | ||
} from '@app/store/ordinals/ordinals.slice'; | ||
|
||
function StatusIcon({ status }: { status: OrdinalsbotInscriptionStatus }) { | ||
switch (status) { | ||
case 'pending': | ||
return <StatusPending />; | ||
case 'paid': | ||
return <StatusPending />; | ||
case 'waiting-for-indexer': | ||
return <StatusPending />; | ||
case 'ready': | ||
return <StatusReady />; | ||
default: | ||
return null; | ||
} | ||
} | ||
function StatusLabel({ status }: { status: OrdinalsbotInscriptionStatus }) { | ||
switch (status) { | ||
case 'pending': | ||
return <>Paying for transfer inscription…</>; | ||
case 'paid': | ||
return ( | ||
<Tooltip label="Your funds have been received. Your inscription will be available shortly."> | ||
<Text>Creating transfer inscription…</Text> | ||
</Tooltip> | ||
); | ||
case 'waiting-for-indexer': | ||
return ( | ||
<Tooltip label="Inscription complete, awaiting metadata"> | ||
<Text>Receiving transfer inscription…</Text> | ||
</Tooltip> | ||
); | ||
case 'ready': | ||
return <Text>Ready to transfer</Text>; | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
export function PendingBrc20TransferList() { | ||
const transferOrders = usePendingBrc20Transfers(); | ||
|
||
useCheckOrderStatuses( | ||
transferOrders.filter(order => order.status !== 'ready').map(order => order.id) | ||
); | ||
|
||
if (!transferOrders.length) return null; | ||
|
||
return ( | ||
<Flex flexDirection="column" justifyContent="space-between" flex={1} my="base-loose"> | ||
<Flex columnGap="8px"> | ||
<Caption>Pending BRC-20 transfers</Caption> | ||
</Flex> | ||
<Stack mt="tight"> | ||
{transferOrders.map(order => ( | ||
<PendingBrcTransfer key={order.id} order={order} /> | ||
))} | ||
</Stack> | ||
</Flex> | ||
); | ||
} | ||
|
||
interface PendingBrcTransferProps { | ||
order: PendingBrc20Transfer; | ||
} | ||
function PendingBrcTransfer({ order }: PendingBrcTransferProps) { | ||
const [component, bind] = usePressable(order.status === 'ready'); | ||
const navigate = useNavigate(); | ||
const ordinalsbotClient = useOrdinalsbotClient(); | ||
|
||
return ( | ||
<Box | ||
key={order.id} | ||
my="base-tight" | ||
onClick={ | ||
order.status === 'ready' | ||
? async () => { | ||
// Really inefficient, find way to not have to refetch data | ||
const { data: orderInfo } = await ordinalsbotClient.orderStatus(order.id); | ||
const { data: inscription } = await fetchInscripionById( | ||
(orderInfo as any).files[0].tx?.inscription | ||
); | ||
navigate(RouteUrls.SendOrdinalInscription, { | ||
state: { | ||
inscription: convertInscriptionToSupportedInscriptionType({ | ||
...inscription, | ||
addressIndex: 0, | ||
}), | ||
}, | ||
}); | ||
} | ||
: noop | ||
} | ||
{...(order.status === 'ready' ? bind : {})} | ||
> | ||
<Text> | ||
{order.amount} {order.tick} | ||
</Text> | ||
<Stack isInline width="100%" mt="tight"> | ||
<CaptionDotSeparator> | ||
<Flex as={Caption}> | ||
<Flag | ||
ml="tight" | ||
align="middle" | ||
spacing="tight" | ||
img={<StatusIcon status={order.status} />} | ||
> | ||
<StatusLabel status={order.status} /> | ||
</Flag> | ||
</Flex> | ||
</CaptionDotSeparator> | ||
</Stack> | ||
{component} | ||
</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
26 changes: 25 additions & 1 deletion
26
src/app/pages/send/choose-crypto-asset/components/crypto-asset-list.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 |
---|---|---|
@@ -1,17 +1,41 @@ | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
import type { AllTransferableCryptoAssetBalances } from '@shared/models/crypto-asset-balance.model'; | ||
import { RouteUrls } from '@shared/route-urls'; | ||
|
||
import { Brc20TokenAssetItem } from '@app/components/crypto-assets/bitcoin/brc20-token-asset/brc20-token-asset-item'; | ||
import { Brc20Token } from '@app/query/bitcoin/ordinals/brc20/brc20-tokens.query'; | ||
|
||
import { CryptoAssetListItem } from './crypto-asset-list-item'; | ||
import { CryptoAssetListLayout } from './crypto-asset-list.layout'; | ||
|
||
interface CryptoAssetListProps { | ||
cryptoAssetBalances: AllTransferableCryptoAssetBalances[]; | ||
brc20Tokens: Brc20Token[]; | ||
} | ||
export function CryptoAssetList({ cryptoAssetBalances }: CryptoAssetListProps) { | ||
export function CryptoAssetList({ cryptoAssetBalances, brc20Tokens }: CryptoAssetListProps) { | ||
const navigate = useNavigate(); | ||
|
||
function navigateToBrc20SendForm(token: Brc20Token) { | ||
const { tick, available_balance } = token; | ||
navigate(RouteUrls.SendBrc20SendForm.replace(':ticker', tick), { | ||
state: { balance: available_balance, tick }, | ||
}); | ||
} | ||
|
||
return ( | ||
<CryptoAssetListLayout> | ||
{cryptoAssetBalances.map(assetBalance => ( | ||
<CryptoAssetListItem assetBalance={assetBalance} key={assetBalance.asset.name} /> | ||
))} | ||
{brc20Tokens.map(token => ( | ||
<Brc20TokenAssetItem | ||
key={token.tick} | ||
token={token} | ||
isPressable={true} | ||
onClick={() => navigateToBrc20SendForm(token)} | ||
/> | ||
))} | ||
</CryptoAssetListLayout> | ||
); | ||
} |
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
Oops, something went wrong.