Skip to content

Commit

Permalink
refactor: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fbwoolf committed Dec 10, 2024
1 parent 96ef2c5 commit e0cac9a
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 156 deletions.
7 changes: 5 additions & 2 deletions src/app/components/nonce-setter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import { useFormikContext } from 'formik';

import { useNextNonce } from '@leather.io/query';

import { StacksSendFormValues, StacksTransactionFormValues } from '@shared/models/form.model';
import {
StacksSendFormValues,
StacksTransactionFormValues,
type SwapFormValues,
} from '@shared/models/form.model';

import type { SwapFormValues } from '@app/pages/swap/hooks/use-swap-form';
import { useCurrentStacksAccountAddress } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks';

export function NonceSetter() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import SBtcAvatarIconSrc from '@assets/avatars/sbtc-avatar-icon.png';
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 type { SbtcDepositInfo } from '@app/query/sbtc/sbtc-deposits.query';

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

interface SBtcDepositTransactionItemProps {
deposit: SBtcDepositInfo;
interface SbtcDepositTransactionItemProps {
deposit: SbtcDepositInfo;
}
export function SBtcDepositTransactionItem({ deposit }: SBtcDepositTransactionItemProps) {
export function SbtcDepositTransactionItem({ deposit }: SbtcDepositTransactionItemProps) {
const { handleOpenBitcoinTxLink: handleOpenTxLink } = useBitcoinExplorerLink();

const openTxLink = () => {
Expand All @@ -28,7 +28,7 @@ export function SBtcDepositTransactionItem({ deposit }: SBtcDepositTransactionIt
txIcon={
// Replace with sBTC avatar icon
<Avatar.Root>
<Avatar.Image alt="ST" src={SBtcAvatarIconSrc} />
<Avatar.Image alt="ST" src={SbtcAvatarIconSrc} />
</Avatar.Root>
}
txStatus={<Caption color="yellow.action-primary-default">Pending</Caption>}
Expand Down
12 changes: 6 additions & 6 deletions src/app/features/activity-list/activity-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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 { 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';
Expand Down Expand Up @@ -64,8 +64,8 @@ export function ActivityList() {
[nsPendingTxs, trPendingTxs]
);

const { isLoading: isLoadingSBtcDeposits, pendingSBtcDeposits } =
useSBtcPendingDeposits(stxAddress);
const { isLoading: isLoadingSbtcDeposits, pendingSbtcDeposits } =
useSbtcPendingDeposits(stxAddress);

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

const transactionListBitcoinTxs = useMemo(() => {
return convertBitcoinTxsToListType(
Expand All @@ -106,7 +106,7 @@ export function ActivityList() {
const hasPendingTransactions =
bitcoinPendingTxs.length > 0 ||
stacksPendingTransactions.length > 0 ||
pendingSBtcDeposits.length > 0;
pendingSbtcDeposits.length > 0;
const hasTransactions =
transactionListBitcoinTxs.length > 0 || transactionListStacksTxs.length > 0;

Expand Down Expand Up @@ -135,7 +135,7 @@ export function ActivityList() {
{hasPendingTransactions && (
<PendingTransactionList
bitcoinTxs={isBitcoinEnabled ? bitcoinPendingTxs : []}
sBtcDeposits={pendingSBtcDeposits}
sBtcDeposits={pendingSbtcDeposits}
stacksTxs={stacksPendingTransactions}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { MempoolTransaction } from '@stacks/stacks-blockchain-api-types';
import type { BitcoinTx } from '@leather.io/models';

import { BitcoinTransactionItem } from '@app/components/bitcoin-transaction-item/bitcoin-transaction-item';
import { SBtcDepositTransactionItem } from '@app/components/sbtc-deposit-status-item/sbtc-deposit-status-item';
import { SbtcDepositTransactionItem } from '@app/components/sbtc-deposit-status-item/sbtc-deposit-status-item';
import { StacksTransactionItem } from '@app/components/stacks-transaction-item/stacks-transaction-item';
import type { SBtcDepositInfo } from '@app/query/sbtc/sbtc-deposits.query';
import type { SbtcDepositInfo } from '@app/query/sbtc/sbtc-deposits.query';

import { PendingTransactionListLayout } from './pending-transaction-list.layout';

interface PendingTransactionListProps {
bitcoinTxs: BitcoinTx[];
sBtcDeposits: SBtcDepositInfo[];
sBtcDeposits: SbtcDepositInfo[];
stacksTxs: MempoolTransaction[];
}
export function PendingTransactionList({
Expand All @@ -25,7 +25,7 @@ export function PendingTransactionList({
<BitcoinTransactionItem key={tx.txid} transaction={tx} />
))}
{sBtcDeposits.map(deposit => (
<SBtcDepositTransactionItem key={deposit.bitcoinTxid} deposit={deposit} />
<SbtcDepositTransactionItem key={deposit.bitcoinTxid} deposit={deposit} />
))}
{stacksTxs.map(tx => (
<StacksTransactionItem key={tx.tx_id} transaction={tx} />
Expand Down
10 changes: 5 additions & 5 deletions src/app/pages/swap/bitflow-swap-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { isError, isUndefined } from '@leather.io/utils';

import { logger } from '@shared/logger';
import type { SwapFormValues } from '@shared/models/form.model';
import { RouteUrls } from '@shared/route-urls';
import { bitflow } from '@shared/utils/bitflow-sdk';

Expand All @@ -27,9 +28,8 @@ import { getCrossChainSwapSubmissionData, getSwapSubmissionData } from './bitflo
import { SwapForm } from './components/swap-form';
import { generateSwapRoutes } from './generate-swap-routes';
import { useBitflowSwap } from './hooks/use-bitflow-swap';
import { useSBtcDepositTransaction } from './hooks/use-sbtc-deposit-transaction';
import { useSbtcDepositTransaction } from './hooks/use-sbtc-deposit-transaction';
import { useStacksBroadcastSwap } from './hooks/use-stacks-broadcast-swap';
import { SwapFormValues } from './hooks/use-swap-form';
import { useSwapNavigate } from './hooks/use-swap-navigate';
import { SwapContext, SwapProvider } from './swap.context';

Expand All @@ -45,7 +45,7 @@ function BitflowSwapContainer() {
const generateUnsignedTx = useGenerateStacksContractCallUnsignedTx();
const signTx = useSignStacksTransaction();
const broadcastStacksSwap = useStacksBroadcastSwap();
const { onDepositSBtc } = useSBtcDepositTransaction();
const { onDepositSbtc } = useSbtcDepositTransaction();

const {
fetchRouteQuote,
Expand Down Expand Up @@ -124,7 +124,7 @@ function BitflowSwapContainer() {

// TODO: Handle cross-chain swaps
if (isCrossChainSwap) {
return await onDepositSBtc(swapSubmissionData);
return await onDepositSbtc(swapSubmissionData);
}

try {
Expand Down Expand Up @@ -195,7 +195,7 @@ function BitflowSwapContainer() {
isCrossChainSwap,
isLoading,
navigate,
onDepositSBtc,
onDepositSbtc,
setIsIdle,
setIsLoading,
signTx,
Expand Down
5 changes: 2 additions & 3 deletions src/app/pages/swap/bitflow-swap.utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import BigNumber from 'bignumber.js';
import type { RouteQuote } from 'bitflow-sdk';
import { P } from 'pino';

import { BtcFeeType, FeeTypes } from '@leather.io/models';
import { type SwapAsset, defaultSwapFee } from '@leather.io/query';
Expand All @@ -9,11 +8,11 @@ import { capitalize, isDefined, microStxToStx } from '@leather.io/utils';
import type { SwapFormValues } from './hooks/use-swap-form';
import type { SwapSubmissionData } from './swap.context';

export function estimateLiquidityFee(dexPath: string[]) {
function estimateLiquidityFee(dexPath: string[]) {
return new BigNumber(dexPath.length).times(0.3).toNumber();
}

export function formatDexPathItem(dex: string) {
function formatDexPathItem(dex: string) {
const name = dex.split('_')[0];
return name === 'ALEX' ? name : capitalize(name.toLowerCase());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {
isUndefined,
} from '@leather.io/utils';

import type { SwapFormValues } from '@shared/models/form.model';
import { RouteUrls } from '@shared/route-urls';

import type { SwapFormValues } from '@app/pages/swap/hooks/use-swap-form';
import { useSwapContext } from '@app/pages/swap/swap.context';

import type { SwapAssetListProps } from './swap-asset-list';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import {
isUndefined,
} from '@leather.io/utils';

import type { SwapFormValues } from '@shared/models/form.model';

import { useShowFieldError } from '@app/common/form-utils';

import { SwapFormValues } from '../../../hooks/use-swap-form';
import { useSwapContext } from '../../../swap.context';

function getPlaceholderValue(name: string, values: SwapFormValues) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { styled } from 'leather-styles/jsx';
import { ArrowsRepeatLeftRightIcon } from '@leather.io/ui';
import { isDefined, isUndefined } from '@leather.io/utils';

import type { SwapFormValues } from '@shared/models/form.model';
import { RouteUrls } from '@shared/route-urls';

import { SwapFormValues } from '../../../hooks/use-swap-form';
import { useSwapContext } from '../../../swap.context';

export function SwapToggleButton() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import {
isUndefined,
} from '@leather.io/utils';

import type { SwapFormValues } from '@shared/models/form.model';
import { RouteUrls } from '@shared/route-urls';

import { useShowFieldError } from '@app/common/form-utils';

import { SwapFormValues } from '../../hooks/use-swap-form';
import { useSwapNavigate } from '../../hooks/use-swap-navigate';
import { useSwapContext } from '../../swap.context';
import { convertInputAmountValueToFiat } from '../../swap.utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { useFormikContext } from 'formik';

import { isUndefined } from '@leather.io/utils';

import type { SwapFormValues } from '@shared/models/form.model';
import { RouteUrls } from '@shared/route-urls';

import { SwapFormValues } from '../../hooks/use-swap-form';
import { SwapAssetItemLayout } from './swap-asset-item.layout';
import { SwapAssetsPairLayout } from './swap-assets-pair.layout';

Expand Down
10 changes: 5 additions & 5 deletions src/app/pages/swap/hooks/use-bitcoin-bridge-assets.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback } from 'react';

import BtcAvatarIconSrc from '@assets/avatars/btc-avatar-icon.png';
import SBtcAvatarIconSrc from '@assets/avatars/sbtc-avatar-icon.png';
import SbtcAvatarIconSrc from '@assets/avatars/sbtc-avatar-icon.png';

import { BTC_DECIMALS } from '@leather.io/constants';
import {
Expand Down Expand Up @@ -37,12 +37,12 @@ export function useBtcSwapAsset() {
}

// Testnet only
const tempContractIdForSBtcTesting =
const tempContractIdForSbtcTesting =
'SNGWPN3XDAQE673MXYXF81016M50NHF5X5PWWM70.sbtc-token::sbtc-token';

export function useSBtcSwapAsset() {
export function useSbtcSwapAsset() {
const stxAddress = useCurrentStacksAccountAddress();
const token = useSip10Token(stxAddress, tempContractIdForSBtcTesting);
const token = useSip10Token(stxAddress, tempContractIdForSbtcTesting);
const bitcoinMarketData = useCryptoCurrencyMarketDataMeanAverage('BTC');

return useCallback((): SwapAsset => {
Expand All @@ -51,7 +51,7 @@ export function useSBtcSwapAsset() {
tokenId: 'token-sbtc',
displayName: 'sBTC',
fallback: 'SB',
icon: SBtcAvatarIconSrc,
icon: SbtcAvatarIconSrc,
name: 'sBTC',
marketData: castBitcoinMarketDataToSbtcMarketData(bitcoinMarketData),
principal: getPrincipalFromContractId(token?.info.contractId ?? ''),
Expand Down
8 changes: 4 additions & 4 deletions src/app/pages/swap/hooks/use-bitflow-swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { bitflow } from '@shared/utils/bitflow-sdk';
import { useCurrentStacksAccountAddress } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks';

import { SwapSubmissionData } from '../swap.context';
import { useBtcSwapAsset, useSBtcSwapAsset } from './use-bitcoin-bridge-assets';
import { useBtcSwapAsset, useSbtcSwapAsset } from './use-bitcoin-bridge-assets';
import { useBitflowSwappableAssets } from './use-bitflow-swappable-assets';

export function useBitflowSwap() {
Expand All @@ -24,15 +24,15 @@ export function useBitflowSwap() {

// Bridge assets
const createBtcAsset = useBtcSwapAsset();
const createSBtcAsset = useSBtcSwapAsset();
const createSbtcAsset = useSbtcSwapAsset();

const swappableAssetsBase = useMemo(
() => [createBtcAsset(), ...migratePositiveAssetBalancesToTop(bitflowSwapAssets)],
[bitflowSwapAssets, createBtcAsset]
);
const swappableAssetsQuote = useMemo(
() => [createSBtcAsset(), ...bitflowSwapAssets],
[bitflowSwapAssets, createSBtcAsset]
() => [createSbtcAsset(), ...bitflowSwapAssets],
[bitflowSwapAssets, createSbtcAsset]
);

const fetchRouteQuote = useCallback(
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/swap/hooks/use-sbtc-deposit-transaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type { SwapSubmissionData } from '../swap.context';

const client = new SbtcApiClientTestnet();

export function useSBtcDepositTransaction() {
export function useSbtcDepositTransaction() {
const toast = useToast();
const { setIsIdle } = useLoading(LoadingKeys.SUBMIT_SWAP_TRANSACTION);
const stacksAccount = useCurrentStacksAccount();
Expand All @@ -32,7 +32,7 @@ export function useSBtcDepositTransaction() {
const navigate = useNavigate();

return {
async onDepositSBtc(swapSubmissionData: SwapSubmissionData) {
async onDepositSbtc(swapSubmissionData: SwapSubmissionData) {
if (!stacksAccount) throw new Error('No stacks account');
if (!utxos) throw new Error('No utxos');
console.log('amount', btcToSat(swapSubmissionData.swapAmountQuote).toNumber());
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/swap/hooks/use-swap-assets-from-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { useNavigate, useParams } from 'react-router-dom';

import { useFormikContext } from 'formik';

import type { SwapFormValues } from '@shared/models/form.model';
import { RouteUrls } from '@shared/route-urls';

import { useSwapContext } from '../swap.context';
import type { SwapFormValues } from './use-swap-form';

export function useSwapAssetsFromRoute() {
const { swappableAssetsBase, swappableAssetsQuote } = useSwapContext();
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/swap/swap.context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createContext, useContext } from 'react';

import type { SwapAsset } from '@leather.io/query';

import { SwapFormValues } from './hooks/use-swap-form';
import type { SwapFormValues } from '@shared/models/form.model';

export interface SwapSubmissionData extends SwapFormValues {
liquidityFee: number;
Expand Down
3 changes: 2 additions & 1 deletion src/app/pages/swap/swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import { useFormikContext } from 'formik';
import { Button } from '@leather.io/ui';
import { isUndefined } from '@leather.io/utils';

import type { SwapFormValues } from '@shared/models/form.model';

import { Card } from '@app/components/layout';
import { LoadingSpinner } from '@app/components/loading-spinner';

import { SwapAssetSelectBase } from './components/swap-asset-select/swap-asset-select-base';
import { SwapAssetSelectQuote } from './components/swap-asset-select/swap-asset-select-quote';
import { useSwapAssetsFromRoute } from './hooks/use-swap-assets-from-route';
import { SwapFormValues } from './hooks/use-swap-form';
import { useSwapContext } from './swap.context';

export function Swap() {
Expand Down
Loading

0 comments on commit e0cac9a

Please sign in to comment.