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/UI refactor fixes #4641

Merged
merged 18 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ module.exports = {
'@typescript-eslint/no-unnecessary-condition': 'off',
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
'@typescript-eslint/array-type': ['error'],
'@typescript-eslint/method-signature-style': ['error', 'method'],
'no-warning-comments': [0],

'react-hooks/rules-of-hooks': 'error',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
"@actions/core": "1.10.1",
"@btckit/types": "0.0.19",
"@leather-wallet/prettier-config": "0.0.1",
"@leather-wallet/tokens": "0.0.2",
"@ls-lint/ls-lint": "2.1.0",
"@pandacss/dev": "0.18.3",
"@playwright/test": "1.38.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export function useGetLegacyAuthBitcoinAddresses() {
p2tr: bytesToHex(taprootAccount?.mainnet?.keychain.publicKey!),
p2wpkh: bytesToHex(nativeSegwitAccount?.mainnet?.keychain.publicKey!),
},
btcPublicKeyTestnet: {
p2tr: bytesToHex(taprootAccount?.testnet?.keychain.publicKey!),
p2wpkh: bytesToHex(nativeSegwitAccount?.testnet?.keychain.publicKey!),
},
};
};
}
2 changes: 1 addition & 1 deletion src/app/common/hooks/use-bitcoin-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export function useBitcoinContracts() {
const txMoney = createMoneyFromDecimal(bitcoinValue, 'BTC');
const txFiatValue = i18nFormatCurrency(calculateFiatValue(txMoney)).toString();
const txFiatValueSymbol = bitcoinMarketData.price.symbol;
const txLink = { blockchain: 'bitcoin', txId };
const txLink = { blockchain: 'bitcoin', txid: txId };

return {
txId,
Expand Down
25 changes: 25 additions & 0 deletions src/app/common/hooks/use-bitcoin-explorer-link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useCallback } from 'react';

import { makeBitcoinTxExplorerLink } from '@app/common/utils';
import { useCurrentNetworkState } from '@app/store/networks/networks.hooks';

import { openInNewTab } from '../utils/open-in-new-tab';

interface HandleOpenBitcoinTxLinkArgs {
txid: string;
}

export function useBitcoinExplorerLink() {
const { chain } = useCurrentNetworkState();
const { bitcoin } = chain;
const handleOpenBitcoinTxLink = useCallback(
({ txid }: HandleOpenBitcoinTxLinkArgs) => {
openInNewTab(makeBitcoinTxExplorerLink({ txid, bitcoin }));
},
[bitcoin]
);

return {
handleOpenBitcoinTxLink,
};
}
2 changes: 1 addition & 1 deletion src/app/common/hooks/use-copy-to-clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

interface UiClipboard {
value: string;
onCopy: () => void;
onCopy(): void;
hasCopied: boolean;
}

Expand All @@ -18,7 +18,7 @@
const selected = curSelection && curSelection.rangeCount > 0 ? curSelection.getRangeAt(0) : false;
el.select();

document.execCommand('copy');

Check warning on line 21 in src/app/common/hooks/use-copy-to-clipboard.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

'execCommand' is deprecated. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/execCommand)

Check warning on line 21 in src/app/common/hooks/use-copy-to-clipboard.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

'execCommand' is deprecated. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/execCommand)

Check warning on line 21 in src/app/common/hooks/use-copy-to-clipboard.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

'execCommand' is deprecated. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/execCommand)
document.body.removeChild(el);
if (selected) {
document.getSelection()?.removeAllRanges();
Expand Down
26 changes: 0 additions & 26 deletions src/app/common/hooks/use-explorer-link.ts

This file was deleted.

25 changes: 25 additions & 0 deletions src/app/common/hooks/use-stacks-explorer-link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useCallback } from 'react';

import { makeStacksTxExplorerLink } from '@app/common/utils';
import { useCurrentNetworkState } from '@app/store/networks/networks.hooks';

import { openInNewTab } from '../utils/open-in-new-tab';

export interface HandleOpenStacksTxLinkArgs {
suffix?: string;
txid: string;
}
export function useStacksExplorerLink() {
const { mode } = useCurrentNetworkState();

const handleOpenStacksTxLink = useCallback(
({ suffix, txid }: HandleOpenStacksTxLinkArgs) => {
openInNewTab(makeStacksTxExplorerLink({ mode, suffix, txid }));
},
[mode]
);

return {
handleOpenStacksTxLink,
};
}
4 changes: 2 additions & 2 deletions src/app/common/psbt/use-psbt-request-params.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo } from 'react';

import { ensureArray, undefinedIfLengthZero } from '@shared/utils';
import { ensureArray, isDefined, undefinedIfLengthZero } from '@shared/utils';

import { useDefaultRequestParams } from '../hooks/use-default-request-search-params';
import { initialSearchParams } from '../initial-search-params';
Expand All @@ -20,7 +20,7 @@ export function usePsbtRequestSearchParams() {
origin,
payload,
requestToken,
signAtIndex: payload?.signAtIndex
signAtIndex: isDefined(payload?.signAtIndex)
? undefinedIfLengthZero(ensureArray(payload?.signAtIndex).map(h => Number(h)))
: undefined,
tabId: tabId ?? 1,
Expand Down
2 changes: 1 addition & 1 deletion src/app/common/theme-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const getThemeLabel = (theme: UserSelectedTheme) => {
const ThemeContext = createContext<{
theme: ComputedTheme;
userSelectedTheme: UserSelectedTheme;
setUserSelectedTheme: (theme: UserSelectedTheme) => void;
setUserSelectedTheme(theme: UserSelectedTheme): void;
}>({
// These values are not used, but are set to satisfy the context's value type.
theme: 'light',
Expand Down
17 changes: 0 additions & 17 deletions src/app/common/transactions/bitcoin/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,6 @@ import { truncateMiddle } from '@app/ui/utils/truncate-middle';

import { BtcSizeFeeEstimator } from './fees/btc-size-fee-estimator';

type BtcTxStatus = 'pending' | 'success';
type BtcStatusColorMap = Record<BtcTxStatus, string>;

const statusFromBitcoinTx = (tx: BitcoinTx): BtcTxStatus => {
if (tx.status.confirmed) return 'success';
return 'pending';
};

export const getColorFromBitcoinTx = (tx: BitcoinTx) => {
const colorMap: BtcStatusColorMap = {
pending: 'warning.label',
success: 'stacks',
};

return colorMap[statusFromBitcoinTx(tx)] ?? 'feedback-error';
};

export function containsTaprootInput(tx: BitcoinTx) {
return tx.vin.some(input => input.prevout.scriptpubkey_type === 'v1_p2tr');
}
Expand Down
37 changes: 25 additions & 12 deletions src/app/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import {
} from '@stacks/transactions';
import { toUnicode } from 'punycode';

import { BitcoinNetworkModes, KEBAB_REGEX } from '@shared/constants';
import type { Blockchains } from '@shared/models/blockchain.model';
import { BitcoinChainConfig, BitcoinNetworkModes, KEBAB_REGEX } from '@shared/constants';

export function createNullArrayOfLength(length: number) {
return new Array(length).fill(null);
Expand Down Expand Up @@ -39,23 +38,37 @@ export function extractPhraseFromString(value: string) {
}
}

interface MakeTxExplorerLinkArgs {
blockchain: Blockchains;
interface MakeBitcoinTxExplorerLinkArgs {
txid: string;
bitcoin: BitcoinChainConfig;
}

interface MakeStacksTxExplorerLinkArgs {
mode: BitcoinNetworkModes;
suffix?: string;
txid: string;
}
export function makeTxExplorerLink({
blockchain,

export function makeStacksTxExplorerLink({
mode,
suffix = '',
txid,
}: MakeTxExplorerLinkArgs) {
switch (blockchain) {
case 'bitcoin':
return `https://mempool.space/${mode !== 'mainnet' ? mode + '/' : ''}tx/${txid}`;
case 'stacks':
return `https://explorer.hiro.so/txid/${txid}?chain=${mode}${suffix}`;
}: MakeStacksTxExplorerLinkArgs) {
return `https://explorer.hiro.so/txid/${txid}?chain=${mode}${suffix}`;
}

export function makeBitcoinTxExplorerLink({
txid,
bitcoin: { bitcoinUrl, bitcoinNetwork },
}: MakeBitcoinTxExplorerLinkArgs) {
switch (bitcoinNetwork) {
case 'mainnet':
case 'testnet':
return `https://mempool.space/${
bitcoinNetwork !== 'mainnet' ? bitcoinNetwork + '/' : ''
}tx/${txid}`;
case 'regtest':
return `${bitcoinUrl}/tx/${txid}`;
default:
return '';
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/common/validation/forms/fee-validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { btcToSat, moneyToBaseUnit, stxToMicroStx } from '../../money/unit-conve

interface FeeValidatorFactoryArgs {
availableBalance?: Money;
unitConverter: (unit: string | number | BigNumber) => BigNumber;
validator: (errorMsg: string) => NumberSchema<number | undefined, AnyObject>;
unitConverter(unit: string | number | BigNumber): BigNumber;
validator(errorMsg: string): NumberSchema<number | undefined, AnyObject>;
}
function feeValidatorFactory({
availableBalance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface BitcoinContractEntryPointLayoutProps {
usdBalance?: string;
isLoading?: boolean;
cursor?: 'pointer' | 'default';
onClick: () => void;
onClick(): void;
}
export function BitcoinContractEntryPointLayout(props: BitcoinContractEntryPointLayoutProps) {
const { balance, caption, icon, usdBalance, isLoading, cursor, onClick } = props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface FeesListItemProps {
feeRate: number;
feeType: string;
isSelected?: boolean;
onClick: () => void;
onClick(): void;
}
export function FeesListItem({
arrivesIn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { Circle, CircleProps, Flex } from 'leather-styles/jsx';

import { BitcoinTx } from '@shared/models/transactions/bitcoin-transaction.model';

import { getColorFromBitcoinTx, isBitcoinTxInbound } from '@app/common/transactions/bitcoin/utils';
import { isBitcoinTxInbound } from '@app/common/transactions/bitcoin/utils';
import { ArrowDownIcon } from '@app/ui/components/icons/arrow-down-icon';
import { ArrowUpIcon } from '@app/ui/components/icons/arrow-up-icon';
import { BtcIcon } from '@app/ui/components/icons/btc-icon';

export function TxStatusIcon(props: { address: string; tx: BitcoinTx }) {
function TxStatusIcon(props: { address: string; tx: BitcoinTx }) {
const { address, tx } = props;
if (isBitcoinTxInbound(address, tx)) return <ArrowDownIcon size="xs" />;
return <ArrowUpIcon size="xs" />;
Expand All @@ -16,21 +15,23 @@ export function TxStatusIcon(props: { address: string; tx: BitcoinTx }) {
interface TransactionIconProps extends CircleProps {
transaction: BitcoinTx;
btcAddress: string;
icon: React.ReactNode;
}
export function BitcoinTransactionIcon({
transaction,
btcAddress,
icon,
...props
}: TransactionIconProps) {
return (
<Flex position="relative">
<BtcIcon />
{icon}
<Circle
bottom="-2px"
right="-9px"
position="absolute"
size="21px"
bg={getColorFromBitcoinTx(transaction)}
bg={transaction.status.confirmed ? 'stacks' : 'warning.label'}
color="accent.background-primary"
border="background"
{...props}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import { Box, Circle, Flex } from 'leather-styles/jsx';
import { Circle } from 'leather-styles/jsx';

import { SupportedInscription } from '@shared/models/inscription.model';
import { BitcoinTx } from '@shared/models/transactions/bitcoin-transaction.model';

import { getColorFromBitcoinTx } from '@app/common/transactions/bitcoin/utils';
import { OrdinalIcon } from '@app/ui/components/icons/ordinal-icon';

import { TxStatusIcon } from './bitcoin-transaction-icon';

interface BitcoinTransactionInscriptionIconProps {
inscription: SupportedInscription;
transaction: BitcoinTx;
btcAddress: string;
}

function InscriptionIcon({ inscription, ...rest }: { inscription: SupportedInscription }) {
export function InscriptionIcon({ inscription, ...rest }: { inscription: SupportedInscription }) {
switch (inscription.type) {
case 'image':
return (
Expand Down Expand Up @@ -42,30 +32,3 @@ function InscriptionIcon({ inscription, ...rest }: { inscription: SupportedInscr
return <OrdinalIcon />;
}
}

export function BitcoinTransactionInscriptionIcon({
inscription,
transaction,
btcAddress,
...rest
}: BitcoinTransactionInscriptionIconProps) {
return (
<Flex position="relative">
<InscriptionIcon inscription={inscription} />
<Circle
bottom="-2px"
right="-9px"
position="absolute"
size="21px"
bg={getColorFromBitcoinTx(transaction)}
color="accent.background-primary"
border="background"
{...rest}
>
<Box height="13px" width="13px">
<TxStatusIcon address={btcAddress} tx={transaction} />
</Box>
</Circle>
</Flex>
);
}
Loading
Loading