Skip to content

Commit

Permalink
Merge branch 'dev' into refactor/remove-broadcast-raw-transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarkhanzadian committed Feb 6, 2024
2 parents adee19c + 04e5d0e commit f2f996c
Show file tree
Hide file tree
Showing 28 changed files with 73 additions and 108 deletions.
3 changes: 2 additions & 1 deletion src/app/common/hooks/use-submit-stx-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { bytesToHex } from '@stacks/common';
import { StacksTransaction, broadcastTransaction } from '@stacks/transactions';

import { logger } from '@shared/logger';
import { isError } from '@shared/utils';

import { getErrorMessage } from '@app/common/get-error-message';
import { useRefreshAllAccountData } from '@app/common/hooks/account/use-refresh-all-account-data';
Expand Down Expand Up @@ -59,7 +60,7 @@ export function useSubmitTransactionCallback({ loadingKey }: UseSubmitTransactio
}
} catch (error) {
logger.error('Transaction callback', { error });
onError(error instanceof Error ? error : { name: '', message: '' });
onError(isError(error) ? error : { name: '', message: '' });
setIsIdle();
}
},
Expand Down
3 changes: 2 additions & 1 deletion src/app/common/utils/safe-await.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// TypeScript port of https://github.com/DavidWells/safe-await/
import { isError } from '@shared/utils';

// Native Error types https://mzl.la/2Veh3TR
const nativeExceptions = [
Expand All @@ -19,7 +20,7 @@ function throwNative(error: Error) {
export async function safeAwait<T>(promise: Promise<T>, finallyFn?: () => void) {
return promise
.then(data => {
if (data instanceof Error) {
if (isError(data)) {
throwNative(data);
return [data] as readonly [Error];
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ import { useGetInscriptionsByOutputQuery } from '@app/query/bitcoin/ordinals/ins
import { useCurrentAccountNativeSegwitAddressIndexZero } from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks';
import { BulletSeparator } from '@app/ui/components/bullet-separator/bullet-separator';
import { BtcIcon } from '@app/ui/components/icons/btc-icon';
import { Caption } from '@app/ui/components/typography/caption';

import { TransactionItemLayout } from '../transaction-item/transaction-item.layout';
import { BitcoinTransactionCaption } from './bitcoin-transaction-caption';
import { BitcoinTransactionIcon } from './bitcoin-transaction-icon';
import { InscriptionIcon } from './bitcoin-transaction-inscription-icon';
import { BitcoinTransactionStatus } from './bitcoin-transaction-status';
import { BitcoinTransactionValue } from './bitcoin-transaction-value';

interface BitcoinTransactionItemProps {
transaction: BitcoinTx;
Expand Down Expand Up @@ -76,13 +75,10 @@ export function BitcoinTransactionItem({ transaction }: BitcoinTransactionItemPr

const txCaption = (
<BulletSeparator>
<BitcoinTransactionCaption>{caption}</BitcoinTransactionCaption>
{inscriptionData ? (
<BitcoinTransactionCaption>{inscriptionData.mime_type}</BitcoinTransactionCaption>
) : null}
<Caption>{caption}</Caption>
{inscriptionData ? <Caption>{inscriptionData.mime_type}</Caption> : null}
</BulletSeparator>
);
const txValue = <BitcoinTransactionValue>{value}</BitcoinTransactionValue>;

const title = inscriptionData ? `Ordinal inscription #${inscriptionData.number}` : 'Bitcoin';
const increaseFeeButton = (
Expand All @@ -107,7 +103,7 @@ export function BitcoinTransactionItem({ transaction }: BitcoinTransactionItemPr
}
txStatus={<BitcoinTransactionStatus transaction={transaction} />}
txTitle={<TransactionTitle title={title} />}
txValue={txValue}
txValue={value}
/>
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BitcoinTx } from '@shared/models/transactions/bitcoin-transaction.model';

import { PendingLabel } from '@app/components/transaction/pending-label';
import { BasicTooltip } from '@app/ui/components/tooltip/basic-tooltip';
import { Caption } from '@app/ui/components/typography/caption';

interface BitcoinTransactionStatusProps {
transaction: BitcoinTx;
Expand All @@ -10,5 +11,9 @@ const pendingWaitingMessage =

export function BitcoinTransactionStatus({ transaction }: BitcoinTransactionStatusProps) {
const isPending = !transaction.status.confirmed;
return isPending ? <PendingLabel pendingWaitingMessage={pendingWaitingMessage} /> : null;
return isPending ? (
<BasicTooltip asChild label={pendingWaitingMessage} side="bottom">
<Caption color="warning.label">Pending</Caption>
</BasicTooltip>
) : null;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function MnemonicWordInput({
const [isFocused, setIsFocused] = useState(false);
const isDirty = useIsFieldDirty(name);
return (
<Input.Root hasError={isDirty && !!meta.error} shrink>
<Input.Root hasError={isDirty && !!meta.error} shrink={!!value}>
<Input.Field
// Limitation of the animated label is that we cannot detect
// programatically updated inputs. Here we add an empty place holder to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function IncreaseFeeButton(props: IncreaseFeeButtonProps) {
position="relative"
px="space.02"
py="space.01"
rounded="8px"
rounded="xs"
type="button"
zIndex={999}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { createSearchParams, useLocation, useNavigate } from 'react-router-dom';

import { styled } from 'leather-styles/jsx';

import { StacksTx, TxTransferDetails } from '@shared/models/transactions/stacks-transaction.model';
import { RouteUrls } from '@shared/route-urls';

Expand Down Expand Up @@ -85,22 +83,16 @@ export function StacksTransactionItem({
/>
);
const txStatus = transaction && <StacksTransactionStatus transaction={transaction} />;
const txCaption = (
<styled.span color="accent.text-subdued" textStyle="caption.02" whiteSpace="nowrap">
{caption}
</styled.span>
);
const txValue = <styled.span textStyle="label.02">{value}</styled.span>;

return (
<TransactionItemLayout
openTxLink={openTxLink}
rightElement={isOriginator && isPending ? increaseFeeButton : undefined}
txCaption={txCaption}
txCaption={caption}
txIcon={txIcon}
txStatus={txStatus}
txTitle={<TransactionTitle title={title} />}
txValue={txValue}
txValue={value}
/>
);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { styled } from 'leather-styles/jsx';

import { StacksTx } from '@shared/models/transactions/stacks-transaction.model';

import { isPendingTx } from '@app/common/transactions/stacks/transaction.utils';
import { BasicTooltip } from '@app/ui/components/tooltip/basic-tooltip';
import { Caption } from '@app/ui/components/typography/caption';

import { PendingLabel } from '../transaction/pending-label';
const pendingWaitingMessage =
'This transaction is waiting to be confirmed. Depending on network congestion, this may take anywhere from a few minutes, to a couple of hours.';

interface TransactionStatusProps {
transaction: StacksTx;
Expand All @@ -16,12 +16,14 @@ export function StacksTransactionStatus({ transaction }: TransactionStatusProps)

return (
<>
{isPending && <PendingLabel />}
{isPending && (
<BasicTooltip asChild label={pendingWaitingMessage} side="bottom">
<Caption color="warning.label">Pending</Caption>
</BasicTooltip>
)}
{isFailed && (
<BasicTooltip label={transaction.tx_status} side="bottom">
<styled.span color="error.label" textStyle="label.03">
Failed
</styled.span>
<Caption color="error.label">Failed</Caption>
</BasicTooltip>
)}
</>
Expand Down
12 changes: 5 additions & 7 deletions src/app/components/transaction-item/transaction-item.layout.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ReactNode } from 'react';

import { styled } from 'leather-styles/jsx';
import { HStack, styled } from 'leather-styles/jsx';

import { ItemInteractive } from '@app/ui/components/item/item-interactive';
import { ItemLayout } from '@app/ui/components/item/item.layout';
import { Caption } from '@app/ui/components/typography/caption';

interface TransactionItemLayoutProps {
openTxLink(): void;
Expand All @@ -25,18 +26,15 @@ export function TransactionItemLayout({
txValue,
}: TransactionItemLayoutProps) {
return (
// TODO: Revisit if needed styles position="relative" zIndex={99}
<ItemInteractive onClick={openTxLink}>
<ItemLayout
flagImg={txIcon && txIcon}
titleLeft={txTitle}
captionLeft={
<>
<styled.span color="accent.text-subdued" textStyle="caption.01">
{txCaption}
</styled.span>
<HStack alignItems="center">
<Caption>{txCaption}</Caption>
{txStatus && txStatus}
</>
</HStack>
}
titleRight={
rightElement ? (
Expand Down
28 changes: 0 additions & 28 deletions src/app/components/transaction/pending-label.tsx

This file was deleted.

3 changes: 2 additions & 1 deletion src/app/components/transaction/transaction-title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ export function TransactionTitle(props: TransactionTitleProps) {
return (
<BasicTooltip disabled={!isEllipsisActive} label={title} side="top">
<Title
fontWeight="normal"
fontWeight={500}
overflow="hidden"
ref={ref}
textOverflow="ellipsis"
textStyle="label.02"
whiteSpace="nowrap"
>
{spamFilter(title)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as yup from 'yup';
import { createMoney } from '@shared/models/money.model';
import { BitcoinTx } from '@shared/models/transactions/bitcoin-transaction.model';
import { RouteUrls } from '@shared/route-urls';
import { isError } from '@shared/utils';

import { useAnalytics } from '@app/common/hooks/analytics/use-analytics';
import { useBtcAssetBalance } from '@app/common/hooks/balance/btc/use-btc-balance';
Expand Down Expand Up @@ -122,7 +123,7 @@ export function useBtcIncreaseFee(btcTx: BitcoinTx) {
}

function onError(error: unknown) {
const message = error instanceof Error ? error.message : 'Unknown error';
const message = isError(error) ? error.message : 'Unknown error';
toast.error(message);
navigate(RouteUrls.Home);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import get from 'lodash.get';
import { BitcoinInputSigningConfig } from '@shared/crypto/bitcoin/signer-config';
import { logger } from '@shared/logger';
import { RouteUrls } from '@shared/route-urls';
import { isError } from '@shared/utils';

import { useLocationState, useLocationStateWithCache } from '@app/common/hooks/use-location-state';
import { useScrollLock } from '@app/common/hooks/use-scroll-lock';
Expand Down Expand Up @@ -115,7 +116,7 @@ function LedgerSignBitcoinTxContainer() {
void bitcoinApp.transport.close();
}
} catch (e) {
if (e instanceof Error && checkLockedDeviceError(e)) {
if (isError(e) && checkLockedDeviceError(e)) {
setLatestDeviceResponse({ deviceLocked: true } as any);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import get from 'lodash.get';

import { finalizeAuthResponse } from '@shared/actions/finalize-auth-response';
import { logger } from '@shared/logger';
import { isError } from '@shared/utils';

import { useGetLegacyAuthBitcoinAddresses } from '@app/common/authentication/use-legacy-auth-bitcoin-addresses';
import { useOnboardingState } from '@app/common/hooks/auth/use-onboarding-state';
Expand Down Expand Up @@ -92,7 +93,7 @@ export function LedgerSignJwtContainer() {
const stacks = await prepareLedgerDeviceStacksAppConnection({
setLoadingState: setAwaitingDeviceConnection,
onError(e) {
if (e instanceof Error && checkLockedDeviceError(e)) {
if (isError(e) && checkLockedDeviceError(e)) {
setLatestDeviceResponse({ deviceLocked: true } as any);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import get from 'lodash.get';
import { finalizeMessageSignature } from '@shared/actions/finalize-message-signature';
import { logger } from '@shared/logger';
import { UnsignedMessage, whenSignableMessageOfType } from '@shared/signature/signature-types';
import { isError } from '@shared/utils';

import { useScrollLock } from '@app/common/hooks/use-scroll-lock';
import { delay } from '@app/common/utils';
Expand Down Expand Up @@ -67,7 +68,7 @@ function LedgerSignStacksMsg({ account, unsignedMessage }: LedgerSignMsgProps) {
const stacksApp = await prepareLedgerDeviceStacksAppConnection({
setLoadingState: setAwaitingDeviceConnection,
onError(e) {
if (e instanceof Error && checkLockedDeviceError(e)) {
if (isError(e) && checkLockedDeviceError(e)) {
setLatestDeviceResponse({ deviceLocked: true } as any);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import get from 'lodash.get';

import { logger } from '@shared/logger';
import { RouteUrls } from '@shared/route-urls';
import { isError } from '@shared/utils';

import { useScrollLock } from '@app/common/hooks/use-scroll-lock';
import { appEvents } from '@app/common/publish-subscribe';
Expand Down Expand Up @@ -71,7 +72,7 @@ function LedgerSignStacksTxContainer() {
const stacksApp = await prepareLedgerDeviceStacksAppConnection({
setLoadingState: setAwaitingDeviceConnection,
onError(e) {
if (e instanceof Error && checkLockedDeviceError(e)) {
if (isError(e) && checkLockedDeviceError(e)) {
setLatestDeviceResponse({ deviceLocked: true } as any);
return;
}
Expand Down Expand Up @@ -148,7 +149,7 @@ function LedgerSignStacksTxContainer() {
signedTx,
});
} catch (e) {
ledgerNavigate.toBroadcastErrorStep(e instanceof Error ? e.message : 'Unknown error');
ledgerNavigate.toBroadcastErrorStep(isError(e) ? e.message : 'Unknown error');
return;
}
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import StacksApp from '@zondax/ledger-stacks';
import AppClient from 'ledger-bitcoin';

import { SupportedBlockchains } from '@shared/constants';
import { isError } from '@shared/utils';

import { delay } from '@app/common/utils';

Expand Down Expand Up @@ -73,7 +74,7 @@ export function useRequestLedgerKeys<App extends AppClient | StacksApp>({
onSuccess?.();
} catch (e) {
setAwaitingDeviceConnection(false);
if (e instanceof Error && checkLockedDeviceError(e)) {
if (isError(e) && checkLockedDeviceError(e)) {
setLatestDeviceResponse({ deviceLocked: true } as any);
return;
}
Expand Down
Loading

0 comments on commit f2f996c

Please sign in to comment.