Skip to content

Commit

Permalink
Merge branch 'dev' into fix/ledger-no-request-keys-context
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarkhanzadian authored Feb 1, 2024
2 parents 7d38f68 + 666fa37 commit 8096b8a
Show file tree
Hide file tree
Showing 52 changed files with 168 additions and 433 deletions.
5 changes: 1 addition & 4 deletions src/app/common/hooks/analytics/use-track-switch-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ export function useTrackSwitchAccount() {

return useCallback(
async (address: string, index: number) => {
const accountBalanceCache = queryClient.getQueryData([
'get-address-anchored-stx-balance',
address,
]);
const accountBalanceCache = queryClient.getQueryData(['get-address-stx-balance', address]);
if (!accountBalanceCache) return;
try {
const balances = parseBalanceResponse(accountBalanceCache as any);
Expand Down
30 changes: 14 additions & 16 deletions src/app/common/hooks/balance/stx/use-stx-balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,47 @@ import { baseCurrencyAmountInQuote, subtractMoney } from '@app/common/money/calc
import { i18nFormatCurrency } from '@app/common/money/format-money';
import { useCryptoCurrencyMarketData } from '@app/query/common/market-data/market-data.hooks';
import { createStacksCryptoCurrencyAssetTypeWrapper } from '@app/query/stacks/balance/stacks-ft-balances.utils';
import { useCurrentStacksAccountAnchoredBalances } from '@app/query/stacks/balance/stx-balance.hooks';

import { useStxOutboundValue } from './use-stx-outbound-value';
import { useCurrentStacksAccountBalances } from '@app/query/stacks/balance/stx-balance.hooks';
import { useCurrentAccountMempoolTransactionsBalance } from '@app/query/stacks/mempool/mempool.hooks';

export function useStxBalance() {
const anchoredBalanceQuery = useCurrentStacksAccountAnchoredBalances();
const totalBalance = anchoredBalanceQuery.data?.stx.balance;
const unlockedStxBalance = anchoredBalanceQuery.data?.stx.unlockedStx;
const stxBalanceQuery = useCurrentStacksAccountBalances();
const totalBalance = stxBalanceQuery.data?.stx.balance;
const unlockedStxBalance = stxBalanceQuery.data?.stx.unlockedStx;

const stxMarketData = useCryptoCurrencyMarketData('STX');
const stxOutboundQuery = useStxOutboundValue();
const pendingTxsBalance = useCurrentAccountMempoolTransactionsBalance();

const stxEffectiveBalance = isDefined(totalBalance)
? subtractMoney(totalBalance, stxOutboundQuery.data)
? subtractMoney(totalBalance, pendingTxsBalance)
: createMoney(0, 'STX');

const stxEffectiveUsdBalance = isDefined(totalBalance)
? i18nFormatCurrency(baseCurrencyAmountInQuote(stxEffectiveBalance, stxMarketData))
: undefined;

const stxLockedBalance = anchoredBalanceQuery.data?.stx.locked;
const stxLockedBalance = stxBalanceQuery.data?.stx.locked;
const stxUsdLockedBalance = isDefined(stxLockedBalance)
? i18nFormatCurrency(baseCurrencyAmountInQuote(stxLockedBalance, stxMarketData))
: undefined;

return useMemo(() => {
return {
anchoredBalanceQuery,
stxOutboundQuery,
isLoading: anchoredBalanceQuery.isLoading || stxOutboundQuery.isLoading,
stxBalanceQuery,
stxOutboundQuery: pendingTxsBalance,
availableBalance: isDefined(unlockedStxBalance)
? subtractMoney(unlockedStxBalance, stxOutboundQuery.data)
? subtractMoney(unlockedStxBalance, pendingTxsBalance)
: createMoney(0, 'STX'),
stxEffectiveBalance: createStacksCryptoCurrencyAssetTypeWrapper(stxEffectiveBalance.amount),
stxEffectiveUsdBalance,
stxLockedBalance,
stxUsdLockedBalance,
};
}, [
anchoredBalanceQuery,
stxOutboundQuery,
stxBalanceQuery,
pendingTxsBalance,
unlockedStxBalance,
stxEffectiveBalance,
stxEffectiveBalance.amount,
stxEffectiveUsdBalance,
stxLockedBalance,
stxUsdLockedBalance,
Expand Down
19 changes: 0 additions & 19 deletions src/app/common/hooks/balance/stx/use-stx-outbound-value.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/app/common/hooks/balance/use-total-balance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createMoney } from '@shared/models/money.model';
import { baseCurrencyAmountInQuote } from '@app/common/money/calculate-money';
import { i18nFormatCurrency } from '@app/common/money/format-money';
import { useCryptoCurrencyMarketData } from '@app/query/common/market-data/market-data.hooks';
import { useAnchoredStacksAccountBalances } from '@app/query/stacks/balance/stx-balance.hooks';
import { useStacksAccountBalances } from '@app/query/stacks/balance/stx-balance.hooks';

import { useBtcAssetBalance } from './btc/use-btc-balance';

Expand All @@ -20,7 +20,7 @@ export function useTotalBalance({ btcAddress, stxAddress }: UseTotalBalanceArgs)
const stxMarketData = useCryptoCurrencyMarketData('STX');

// get stx balance
const { data: balances, isLoading } = useAnchoredStacksAccountBalances(stxAddress);
const { data: balances, isLoading } = useStacksAccountBalances(stxAddress);
const stxBalance = balances ? balances.stx.balance : createMoney(0, 'STX');

// get btc balance
Expand Down
4 changes: 2 additions & 2 deletions src/app/common/hooks/use-key-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { queryClient } from '@app/common/persistence';
import { partiallyClearLocalStorage } from '@app/common/store-utils';
import { useAppDispatch } from '@app/store';
import { createNewAccount, stxChainActions } from '@app/store/chains/stx-chain.actions';
import { useBitcoinClient, useStacksClientAnchored } from '@app/store/common/api-clients.hooks';
import { useBitcoinClient, useStacksClient } from '@app/store/common/api-clients.hooks';
import { inMemoryKeyActions } from '@app/store/in-memory-key/in-memory-key.actions';
import { bitcoinKeysSlice } from '@app/store/ledger/bitcoin/bitcoin-key.slice';
import { stacksKeysSlice } from '@app/store/ledger/stacks/stacks-key.slice';
Expand All @@ -23,7 +23,7 @@ export function useKeyActions() {
const analytics = useAnalytics();
const dispatch = useAppDispatch();
const defaultKeyDetails = useCurrentKeyDetails();
const stxClient = useStacksClientAnchored();
const stxClient = useStacksClient();
const btcClient = useBitcoinClient();

return useMemo(
Expand Down
5 changes: 1 addition & 4 deletions src/app/common/transactions/stacks/transaction.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ import { truncateMiddle } from '@app/ui/utils/truncate-middle';
export const statusFromTx = (tx: StacksTx): StacksTxStatus => {
const { tx_status } = tx;
if (tx_status === 'pending') return 'pending';
if (tx_status === 'success')
return 'is_unanchored' in tx && tx.is_unanchored
? 'success_microblock'
: 'success_anchor_block';
if (tx_status === 'success') return 'success';
return 'failed';
};

Expand Down
4 changes: 2 additions & 2 deletions src/app/components/balance-stx.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { useMemo } from 'react';

import { stacksValue } from '@app/common/stacks-utils';
import { useAnchoredStacksAccountBalances } from '@app/query/stacks/balance/stx-balance.hooks';
import { useStacksAccountBalances } from '@app/query/stacks/balance/stx-balance.hooks';
import { Caption } from '@app/ui/components/typography/caption';

interface BalanceProps {
address: string;
}
export function StxBalance(props: BalanceProps) {
const { address } = props;
const { data: balances } = useAnchoredStacksAccountBalances(address);
const { data: balances } = useStacksAccountBalances(address);

const balance = useMemo(
() =>
Expand Down
29 changes: 2 additions & 27 deletions src/app/components/crypto-assets/components/asset-caption.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,12 @@
import { Flex, HStack, styled } from 'leather-styles/jsx';

import { BulletOperator } from '@app/ui/components/bullet-separator/bullet-separator';
import { InfoIcon } from '@app/ui/components/icons/info-icon';
import { BasicTooltip } from '@app/ui/components/tooltip/basic-tooltip';
import { Flex, styled } from 'leather-styles/jsx';

interface AssetCaptionProps {
caption: string;
isUnanchored?: boolean;
}
export function AssetCaption({ caption, isUnanchored }: AssetCaptionProps) {
export function AssetCaption({ caption }: AssetCaptionProps) {
return (
<Flex flexDirection="row">
<styled.span textStyle="caption.02">{caption}</styled.span>{' '}
{isUnanchored ? (
<>
<styled.span mx="space.01" textStyle="caption.02">
<BulletOperator /> Microblock
</styled.span>
<BasicTooltip side="right" label={'Learn more about microblocks'}>
<HStack>
<a
href="https://docs.stacks.co/understand-stacks/microblocks"
target="_blank"
rel="noreferrer"
>
<InfoIcon color="accent.text-subdued" ml="space.01" size="xs" />
</a>
</HStack>
</BasicTooltip>
</>
) : (
''
)}
</Flex>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@ import { Box, BoxProps } from 'leather-styles/jsx';

import { DynamicColorCircle } from '@app/ui/components/dynamic-color-circle';

import { StacksUnanchoredStatusIcon } from './stacks-unanchored-status-icon';
import { StxAvatar } from './stx-avatar';

interface StacksAssetAvatarProps extends BoxProps {
gradientString?: string;
imageCanonicalUri?: string;
isStx?: boolean;
isUnanchored?: boolean;
size?: string;
}
export function StacksAssetAvatar({
children,
gradientString,
imageCanonicalUri,
isStx,
isUnanchored,
size = '36',
...props
}: StacksAssetAvatarProps) {
Expand All @@ -33,7 +30,6 @@ export function StacksAssetAvatar({
return (
<DynamicColorCircle color={color} size={size} value={gradientString}>
<Box position="absolute">{children}</Box>
{isUnanchored ? <StacksUnanchoredStatusIcon /> : null}
</DynamicColorCircle>
);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import { Circle, CircleProps } from 'leather-styles/jsx';

import { StxIcon } from '@app/ui/components/icons/stx-icon';

import { StacksUnanchoredStatusIcon } from './stacks-unanchored-status-icon';

interface StxAvatarProps extends CircleProps {
isUnanchored?: boolean;
}
export function StxAvatar({ isUnanchored, ...props }: StxAvatarProps) {
export function StxAvatar({ ...props }: CircleProps) {
return (
<Circle
bg="stacks"
Expand All @@ -17,7 +12,6 @@ export function StxAvatar({ isUnanchored, ...props }: StxAvatarProps) {
{...props}
>
<StxIcon />
{isUnanchored ? <StacksUnanchoredStatusIcon /> : null}
</Circle>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { CryptoAssetSelectors } from '@tests/selectors/crypto-asset.selectors';
import { FlexProps } from 'leather-styles/jsx';

import type { StacksFungibleTokenAssetBalance } from '@shared/models/crypto-asset-balance.model';
import { Money } from '@shared/models/money.model';

import { getImageCanonicalUri } from '@app/common/crypto-assets/stacks-crypto-asset.utils';
import { formatContractId, getTicker } from '@app/common/utils';
Expand All @@ -13,7 +12,6 @@ import { StacksFungibleTokenAssetItemLayout } from './stacks-fungible-token-asse

interface StacksFungibleTokenAssetItemProps extends FlexProps {
assetBalance: StacksFungibleTokenAssetBalance;
unanchoredAssetBalance?: Money;
isPressable?: boolean;
onClick?(): void;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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 { MicroblockLabel } from '../transaction/microblock-label';
import { PendingLabel } from '../transaction/pending-label';

interface TransactionStatusProps {
Expand All @@ -14,13 +13,10 @@ interface TransactionStatusProps {
export function StacksTransactionStatus({ transaction }: TransactionStatusProps) {
const isPending = isPendingTx(transaction);
const isFailed = !isPending && transaction.tx_status !== 'success';
const isInMicroblock =
!isPending && transaction.tx_status === 'success' && transaction.is_unanchored;

return (
<>
{isPending && <PendingLabel />}
{isInMicroblock && <MicroblockLabel />}
{isFailed && (
<BasicTooltip label={transaction.tx_status} side="bottom">
<styled.span color="error.label" textStyle="label.03">
Expand Down
22 changes: 0 additions & 22 deletions src/app/components/transaction/microblock-label.tsx

This file was deleted.

13 changes: 0 additions & 13 deletions src/app/components/transaction/token-transfer-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,12 @@ import { StacksTx } from '@shared/models/transactions/stacks-transaction.model';
import { useCurrentAccountStxAddressState } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks';
import { ArrowDownIcon } from '@app/ui/components/icons/arrow-down-icon';
import { ArrowUpIcon } from '@app/ui/components/icons/arrow-up-icon';
import { ZapIcon } from '@app/ui/components/icons/zap-icon';

import { getColorFromTx } from './transaction-type-icon';

export function TokenTransferIcon(props: { tx: StacksTx }) {
const { tx } = props;
const currentAccountStxAddress = useCurrentAccountStxAddressState();
const isSent = tx.sender_address === currentAccountStxAddress;

if ('is_unanchored' in tx && tx.is_unanchored)
return (
<ZapIcon
bg={getColorFromTx(tx)}
borderColor="currentColor"
fill="accent.background-primary"
size="xs"
/>
);

if (isSent) return <ArrowUpIcon size="xs" />;

return <ArrowDownIcon size="xs" />;
Expand Down
2 changes: 0 additions & 2 deletions src/app/components/transaction/transaction-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ export function TransactionIcon(props: { tx: StacksTx }) {
return <TokenTransferIcon tx={tx} />;
case 'contract_call':
return <FunctionIcon />;
case 'poison_microblock':
return null;
default:
return null;
}
Expand Down
5 changes: 2 additions & 3 deletions src/app/components/transaction/transaction-type-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import { TransactionTypeIconWrapper } from './transaction-type-icon-wrapper';

type StatusColorMap = Record<StacksTxStatus, string>;

export function getColorFromTx(tx: StacksTx) {
function getColorFromTx(tx: StacksTx) {
const colorMap: StatusColorMap = {
pending: 'warning.label',
success_microblock: 'stacks',
success_anchor_block: 'stacks',
success: 'stacks',
failed: 'error.label',
};

Expand Down
Loading

0 comments on commit 8096b8a

Please sign in to comment.