Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/sbtc updates #6037

Merged
merged 5 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@
"@leather.io/bitcoin": "0.17.0",
"@leather.io/constants": "0.13.5",
"@leather.io/crypto": "1.6.14",
"@leather.io/models": "0.22.0",
"@leather.io/query": "2.26.1",
"@leather.io/models": "0.24.0",
"@leather.io/query": "2.26.9",
"@leather.io/stacks": "1.4.0",
"@leather.io/tokens": "0.12.1",
"@leather.io/ui": "1.44.4",
Expand Down
89 changes: 65 additions & 24 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import SbtcAvatarIconSrc from '@assets/avatars/sbtc-avatar-icon.png';
import { HStack } from 'leather-styles/jsx';

import { Avatar, Caption, Title } from '@leather.io/ui';
import { Avatar, Caption, Link, 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, SbtcStatus } from '@app/query/sbtc/sbtc-deposits.query';
import { openInNewTab } from '@app/common/utils/open-in-new-tab';
import { SbtcDeposit, SbtcStatus } from '@app/query/sbtc/sbtc-deposits.query';

import { TransactionItemLayout } from '../transaction-item/transaction-item.layout';

Expand All @@ -17,37 +19,61 @@ function getDepositStatus(status: SbtcStatus) {
return 'Pending deposit';
case 'accepted':
return 'Pending mint';
case 'confirmed':
return 'Done';
case 'failed':
return 'Failed';
case 'confirmed':
default:
return '';
}
}

function getDepositStatusTextColor(status: SbtcStatus) {
switch (status) {
case 'pending':
case 'reprocessing':
case 'accepted':
return 'yellow.action-primary-default';
case 'failed':
return 'red.action-primary-default';
case 'confirmed':
default:
return '';
}
}

const sbtcReclaimUrl = 'https://app.stacks.co/reclaim?depositTxId=';

interface SbtcDepositTransactionItemProps {
deposit: SbtcDepositInfo;
deposit: SbtcDeposit;
}
export function SbtcDepositTransactionItem({ deposit }: SbtcDepositTransactionItemProps) {
const { handleOpenBitcoinTxLink: handleOpenTxLink } = useBitcoinExplorerLink();
const { bitcoinTxid, status } = deposit;
const depositFailed = status === 'failed';

const openTxLink = () => {
function openTxLink() {
void analytics.track('view_bitcoin_transaction');
handleOpenTxLink({ txid: deposit.bitcoinTxid });
};
handleOpenTxLink({ txid: bitcoinTxid });
}

function openReclaimLink() {
return openInNewTab(`${sbtcReclaimUrl}${bitcoinTxid}`);
}

return (
<TransactionItemLayout
openTxLink={openTxLink}
txCaption={truncateMiddle(deposit.bitcoinTxid, 4)}
openTxLink={!depositFailed ? openTxLink : () => {}}
txCaption={truncateMiddle(bitcoinTxid, 4)}
txIcon={
<Avatar.Root>
<Avatar.Image alt="ST" src={SbtcAvatarIconSrc} />
</Avatar.Root>
}
txStatus={
<Caption color="yellow.action-primary-default">{getDepositStatus(deposit.status)}</Caption>
<HStack>
<Caption color={getDepositStatusTextColor(status)}>{getDepositStatus(status)}</Caption>
{depositFailed && <Link onClick={openReclaimLink}>Reclaim</Link>}
</HStack>
}
txTitle={<Title textStyle="label.02">BTC → sBTC</Title>}
// Api is only returning 0 right now
Expand Down
28 changes: 23 additions & 5 deletions src/app/features/activity-list/activity-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@ import {

import { LoadingSpinner } from '@app/components/loading-spinner';
import { useConfigBitcoinEnabled } from '@app/query/common/remote-config/remote-config.query';
import { useSbtcPendingDeposits } from '@app/query/sbtc/sbtc-deposits.query';
import {
useSbtcConfirmedDeposits,
useSbtcFailedDeposits,
useSbtcPendingDeposits,
} from '@app/query/sbtc/sbtc-deposits.query';
import { useZeroIndexTaprootAddress } from '@app/store/accounts/blockchain/bitcoin/bitcoin.hooks';
import { useCurrentAccountNativeSegwitIndexZeroSigner } from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks';
import { useCurrentStacksAccountAddress } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks';
import { useUpdateSubmittedTransactions } from '@app/store/submitted-transactions/submitted-transactions.hooks';
import { useSubmittedTransactions } from '@app/store/submitted-transactions/submitted-transactions.selectors';

import { convertBitcoinTxsToListType, convertStacksTxsToListType } from './activity-list.utils';
import {
convertBitcoinTxsToListType,
convertSbtcDepositToListType,
convertStacksTxsToListType,
} from './activity-list.utils';
import { NoAccountActivity } from './components/no-account-activity';
import { PendingTransactionList } from './components/pending-transaction-list/pending-transaction-list';
import { SubmittedTransactionList } from './components/submitted-transaction-list/submitted-transaction-list';
Expand Down Expand Up @@ -64,8 +72,12 @@ export function ActivityList() {
[nsPendingTxs, trPendingTxs]
);

const { isLoading: isLoadingSbtcDeposits, pendingSbtcDeposits } =
const { isLoading: isLoadingSbtcPendingDeposits, pendingSbtcDeposits } =
useSbtcPendingDeposits(stxAddress);
const { isLoading: isLoadingSbtcConfirmedDeposits, confirmedSbtcDeposits } =
useSbtcConfirmedDeposits(stxAddress);
const { isLoading: isLoadingSbtcFailedDeposits, failedSbtcDeposits } =
useSbtcFailedDeposits(stxAddress);

const { isLoading: isLoadingStacksTransactions, data: stacksTransactionsWithTransfers } =
useGetAccountTransactionsWithTransfersQuery(stxAddress);
Expand All @@ -85,7 +97,9 @@ export function ActivityList() {
isLoadingTrBitcoinTransactions ||
isLoadingStacksTransactions ||
isLoadingStacksPendingTransactions ||
isLoadingSbtcDeposits;
isLoadingSbtcPendingDeposits ||
isLoadingSbtcConfirmedDeposits ||
isLoadingSbtcFailedDeposits;

const transactionListBitcoinTxs = useMemo(() => {
return convertBitcoinTxsToListType(
Expand Down Expand Up @@ -135,14 +149,18 @@ export function ActivityList() {
{hasPendingTransactions && (
<PendingTransactionList
bitcoinTxs={isBitcoinEnabled ? bitcoinPendingTxs : []}
sBtcDeposits={pendingSbtcDeposits}
sbtcDeposits={pendingSbtcDeposits}
stacksTxs={stacksPendingTransactions}
/>
)}
{hasTransactions && (
<TransactionList
bitcoinTxs={isBitcoinEnabled ? transactionListBitcoinTxs : []}
stacksTxs={transactionListStacksTxs}
sbtcDeposits={convertSbtcDepositToListType([
...confirmedSbtcDeposits,
...failedSbtcDeposits,
])}
currentBitcoinAddress={nsBitcoinAddress}
/>
)}
Expand Down
Loading
Loading