-
Notifications
You must be signed in to change notification settings - Fork 146
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
Showing
7 changed files
with
145 additions
and
10 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/app/components/sbtc-deposit-status-item/sbtc-deposit-status-item.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,40 @@ | ||
import SBtcAvatarIconSrc from '@assets/avatars/sbtc-avatar-icon.png'; | ||
|
||
import { Avatar, Caption, Title } from '@leather.io/ui'; | ||
import { truncateMiddle } from '@leather.io/utils'; | ||
|
||
import { analytics } from '@shared/utils/analytics'; | ||
|
||
import { useBitcoinExplorerLink } from '@app/common/hooks/use-bitcoin-explorer-link'; | ||
import type { SBtcDepositInfo } from '@app/query/sbtc/sbtc-deposits.query'; | ||
|
||
import { TransactionItemLayout } from '../transaction-item/transaction-item.layout'; | ||
|
||
interface SBtcDepositTransactionItemProps { | ||
deposit: SBtcDepositInfo; | ||
} | ||
export function SBtcDepositTransactionItem({ deposit }: SBtcDepositTransactionItemProps) { | ||
const { handleOpenBitcoinTxLink: handleOpenTxLink } = useBitcoinExplorerLink(); | ||
|
||
const openTxLink = () => { | ||
void analytics.track('view_bitcoin_transaction'); | ||
handleOpenTxLink({ txid: deposit.bitcoinTxid }); | ||
}; | ||
|
||
return ( | ||
<TransactionItemLayout | ||
openTxLink={openTxLink} | ||
txCaption={truncateMiddle(deposit.bitcoinTxid, 4)} | ||
txIcon={ | ||
// Replace with sBTC avatar icon | ||
<Avatar.Root> | ||
<Avatar.Image alt="ST" src={SBtcAvatarIconSrc} /> | ||
</Avatar.Root> | ||
} | ||
txStatus={<Caption color="yellow.action-primary-default">Pending</Caption>} | ||
txTitle={<Title textStyle="label.02">BTC → sBTC</Title>} | ||
// Api is only returning 0 right now | ||
txValue={''} // deposit.amount.toString() | ||
/> | ||
); | ||
} |
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,68 @@ | ||
import { hexToBytes } from '@stacks/common'; | ||
import { BytesReader, addressToString, deserializeAddress } from '@stacks/transactions'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import axios from 'axios'; | ||
|
||
export enum SBtcStatus { | ||
Pending = 'pending', | ||
Reprocessing = 'reprocessing', | ||
Accepted = 'accepted', | ||
Confirmed = 'confirmed', | ||
Failed = 'failed', | ||
} | ||
|
||
export interface SBtcDepositInfo { | ||
amount: number; | ||
bitcoinTxOutputIndex: number; | ||
bitcoinTxid: string; | ||
depositScript: string; | ||
lastUpdateBlockHash: string; | ||
lastUpdateHeight: number; | ||
recipient: string; // Stacks address | ||
reclaimScript: string; | ||
status: SBtcStatus; | ||
} | ||
|
||
interface GetSBtcDepositsResponse { | ||
deposits: SBtcDepositInfo[]; | ||
nextToken?: string; | ||
} | ||
|
||
const emilyUrl = 'https://beta.sbtc-emily.com/deposit'; | ||
|
||
async function getSBtcDeposits(status: string): Promise<GetSBtcDepositsResponse> { | ||
const resp = await axios.get(`${emilyUrl}?status=${status}`, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
return resp.data; | ||
} | ||
|
||
export function useGetSBtcDeposits(stxAddress: string, status: string) { | ||
return useQuery({ | ||
queryKey: ['get-sbtc-deposits', stxAddress, status], | ||
queryFn: () => getSBtcDeposits(status), | ||
select: resp => | ||
resp.deposits.filter(deposit => { | ||
const recipient = addressToString( | ||
deserializeAddress(new BytesReader(hexToBytes(deposit.recipient.slice(2)))) | ||
); | ||
return recipient === stxAddress; | ||
}), | ||
}); | ||
} | ||
|
||
export function useSBtcPendingDeposits(stxAddress: string) { | ||
const { data: pendingDeposits = [], isLoading: isLoadingStatusPending } = useGetSBtcDeposits( | ||
stxAddress, | ||
'pending' | ||
); | ||
const { data: reprocessingDeposits = [], isLoading: isLoadingStatusReprocessing } = | ||
useGetSBtcDeposits(stxAddress, 'reprocessing'); | ||
|
||
return { | ||
isLoading: isLoadingStatusPending || isLoadingStatusReprocessing, | ||
pendingSBtcDeposits: [...pendingDeposits, ...reprocessingDeposits], | ||
}; | ||
} |