Skip to content

Commit

Permalink
refactor: currency model imports
Browse files Browse the repository at this point in the history
  • Loading branch information
fbwoolf authored and kyranjamie committed Sep 20, 2024
1 parent 36a84dc commit 54e2865
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 43 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
"@leather.io/bitcoin": "0.11.2",
"@leather.io/constants": "0.9.2",
"@leather.io/crypto": "1.4.2",
"@leather.io/models": "0.13.0",
"@leather.io/models": "0.14.0",
"@leather.io/query": "2.10.0",
"@leather.io/stacks": "1.0.2",
"@leather.io/tokens": "0.9.0",
Expand Down
13 changes: 11 additions & 2 deletions pnpm-lock.yaml

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

4 changes: 2 additions & 2 deletions src/app/common/hooks/use-convert-to-fiat-amount.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useCallback } from 'react';

import type { CryptoCurrencies, Money } from '@leather.io/models';
import type { CryptoCurrency, Money } from '@leather.io/models';
import { useCryptoCurrencyMarketDataMeanAverage } from '@leather.io/query';
import { baseCurrencyAmountInQuote } from '@leather.io/utils';

export function useConvertCryptoCurrencyToFiatAmount(currency: CryptoCurrencies) {
export function useConvertCryptoCurrencyToFiatAmount(currency: CryptoCurrency) {
// TODO: unsafe type assumption
const cryptoCurrencyMarketData = useCryptoCurrencyMarketDataMeanAverage(
currency as 'BTC' | 'STX'
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/fees-row/components/custom-fee-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { SharedComponentsSelectors } from '@tests/selectors/shared-component.sel
import { useField } from 'formik';
import { Flex, Stack, styled } from 'leather-styles/jsx';

import type { CryptoCurrencies, StacksFeeEstimate } from '@leather.io/models';
import type { CryptoCurrency, StacksFeeEstimate } from '@leather.io/models';
import { stxToMicroStx } from '@leather.io/utils';

import { SendFormWarningMessages } from '@app/common/warning-messages';

interface CustomFeeFieldProps {
feeCurrencySymbol: CryptoCurrencies;
feeCurrencySymbol: CryptoCurrency;
lowFeeEstimate: StacksFeeEstimate;
setFieldWarning(value: string): void;
disableFeeSelection?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/fees-row/components/transaction-fee.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { SharedComponentsSelectors } from '@tests/selectors/shared-component.selectors';
import { styled } from 'leather-styles/jsx';

import type { CryptoCurrencies, Money } from '@leather.io/models';
import type { CryptoCurrency, Money } from '@leather.io/models';
import { formatDustUsdAmounts, i18nFormatCurrency } from '@leather.io/utils';

import { BasicTooltip } from '@app/ui/components/tooltip/basic-tooltip';

interface TransactionFeeProps {
fee: string | number;
feeCurrencySymbol: CryptoCurrencies;
feeCurrencySymbol: CryptoCurrency;
usdAmount: Money | null;
}
export function TransactionFee({ fee, feeCurrencySymbol, usdAmount }: TransactionFeeProps) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type React from 'react';

import type { Blockchains, Currencies } from '@leather.io/models';
import type { Blockchains, Currency } from '@leather.io/models';
import { ItemLayout, Pressable } from '@leather.io/ui';

import { capitalize } from '@app/common/utils';
Expand All @@ -12,7 +12,7 @@ import { ConnectLedgerButton } from './connect-ledger-asset-button';
interface ConnectLedgerAssetItemFallbackProps {
chain: Blockchains;
icon: React.ReactNode;
symbol: Currencies;
symbol: Currency;
variant: AssetListVariant;
}
export function ConnectLedgerAssetItemFallback({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useNavigate } from 'react-router-dom';

import { AuthType, StacksTransaction } from '@stacks/transactions';

import type { CryptoCurrencies } from '@leather.io/models';
import type { CryptoCurrency } from '@leather.io/models';
import { delay, isError, isString } from '@leather.io/utils';

import { finalizeTxSignature } from '@shared/actions/finalize-tx-signature';
Expand All @@ -25,7 +25,7 @@ async function simulateShortDelayToAvoidUndefinedTabId() {
}

interface UseStacksBroadcastTransactionArgs {
token: CryptoCurrencies;
token: CryptoCurrency;
decimals?: number;
isIncreaseFeeTransaction?: boolean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '@stacks/transactions';
import BigNumber from 'bignumber.js';

import type { CryptoCurrencies } from '@leather.io/models';
import type { CryptoCurrency } from '@leather.io/models';
import {
useCryptoCurrencyMarketDataMeanAverage,
useGetStacksNetworkBlockTimeQuery,
Expand All @@ -30,7 +30,7 @@ import { getEstimatedConfirmationTime } from '@app/common/transactions/stacks/tr
import { removeTrailingNullCharacters } from '@app/common/utils';
import { useCurrentNetworkState } from '@app/store/networks/networks.hooks';

export function useStacksTransactionSummary(token: CryptoCurrencies) {
export function useStacksTransactionSummary(token: CryptoCurrency) {
// TODO: unsafe type assumption
const tokenMarketData = useCryptoCurrencyMarketDataMeanAverage(token as 'BTC' | 'STX');
const { isTestnet } = useCurrentNetworkState();
Expand Down
10 changes: 5 additions & 5 deletions src/app/pages/fund/components/fiat-providers.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import OkxIcon from '@assets/images/fund/fiat-providers/okx-icon.png';
import TransakIcon from '@assets/images/fund/fiat-providers/transak-icon.png';
import { generateOnRampURL } from '@coinbase/cbpay-js';

import type { CryptoCurrencies } from '@leather.io/models';
import type { CryptoCurrency } from '@leather.io/models';

import { COINBASE_APP_ID, MOONPAY_API_KEY, TRANSAK_API_KEY } from '@shared/environment';

Expand Down Expand Up @@ -43,7 +43,7 @@ export const activeFiatProviderIcons: Record<ActiveFiatProvider['name'], string>
[ActiveFiatProviders.Transak]: TransakIcon,
};

function makeCoinbaseUrl(address: string, symbol: CryptoCurrencies) {
function makeCoinbaseUrl(address: string, symbol: CryptoCurrency) {
const code = symbol.toUpperCase();

const onRampURL = generateOnRampURL({
Expand All @@ -58,12 +58,12 @@ function makeCoinbaseUrl(address: string, symbol: CryptoCurrencies) {
return onRampURL;
}

function makeMoonPayUrl(address: string, symbol: CryptoCurrencies) {
function makeMoonPayUrl(address: string, symbol: CryptoCurrency) {
const code = symbol.toLowerCase();
return `https://buy.moonpay.com?apiKey=${MOONPAY_API_KEY}&currencyCode=${code}&walletAddress=${address}`;
}

function makeTransakUrl(address: string, symbol: CryptoCurrencies) {
function makeTransakUrl(address: string, symbol: CryptoCurrency) {
const screenTitle = 'Buy Stacks';
const code = symbol.toUpperCase();

Expand All @@ -82,7 +82,7 @@ interface GetProviderNameArgs {
hasFastCheckoutProcess: boolean;
key: string;
name: string;
symbol: CryptoCurrencies;
symbol: CryptoCurrency;
}
export function getProviderUrl({
address,
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/fund/components/fund.layout.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Stack, styled } from 'leather-styles/jsx';

import type { Blockchains, CryptoCurrencies } from '@leather.io/models';
import type { Blockchains, CryptoCurrency } from '@leather.io/models';

import { HasChildren } from '@app/common/has-children';

interface FundLayoutProps extends HasChildren {
blockchain: Blockchains;
symbol: CryptoCurrencies;
symbol: CryptoCurrency;
}
export function FundLayout({ blockchain, symbol, children }: FundLayoutProps) {
return (
Expand Down
6 changes: 3 additions & 3 deletions src/app/pages/fund/components/receive-funds-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import QRCodeIcon from '@assets/images/fund/qr-code-icon.png';
import { FundPageSelectors } from '@tests/selectors/fund.selectors';

import type { CryptoCurrencies } from '@leather.io/models';
import type { CryptoCurrency } from '@leather.io/models';

import { FundAccountTile } from './fund-account-tile';
import { BitcoinIconComponent, StacksIconComponent } from './icon-components';
Expand All @@ -13,7 +13,7 @@ interface CryptoDescription {
IconComponent(): React.JSX.Element;
}

const cryptoDescriptions: Record<CryptoCurrencies, CryptoDescription> = {
const cryptoDescriptions: Record<CryptoCurrency, CryptoDescription> = {
STX: {
title: 'Receive STX from a friend or deposit from a separate wallet',
IconComponent: StacksIconComponent,
Expand All @@ -25,7 +25,7 @@ const cryptoDescriptions: Record<CryptoCurrencies, CryptoDescription> = {
};
interface ReceiveStxItemProps {
onReceive(): void;
symbol: CryptoCurrencies;
symbol: CryptoCurrency;
}
export function ReceiveFundsItem({ onReceive, symbol }: ReceiveStxItemProps) {
return (
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/fund/fiat-providers-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useLocation, useNavigate } from 'react-router-dom';

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

import type { CryptoCurrencies } from '@leather.io/models';
import type { CryptoCurrency } from '@leather.io/models';

import { analytics } from '@shared/utils/analytics';

Expand All @@ -20,7 +20,7 @@ import { ReceiveFundsItem } from './components/receive-funds-item';
interface FiatProvidersProps {
address: string;
route: string;
symbol: CryptoCurrencies;
symbol: CryptoCurrency;
}
export function FiatProvidersList(props: FiatProvidersProps) {
const { address, route, symbol } = props;
Expand Down
9 changes: 4 additions & 5 deletions src/app/pages/fund/fund.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Outlet, useParams } from 'react-router-dom';
import type {
Blockchains,
BtcCryptoAssetBalance,
CryptoCurrencies,
CryptoCurrency,
StxCryptoAssetBalance,
} from '@leather.io/models';

Expand All @@ -23,15 +23,15 @@ interface FundCryptoCurrencyInfo {
balance?: BtcCryptoAssetBalance | StxCryptoAssetBalance;
blockchain: Blockchains;
route: string;
symbol: CryptoCurrencies;
symbol: CryptoCurrency;
}

export function FundPage() {
const currentStxAccount = useCurrentStacksAccount();
const bitcoinSigner = useCurrentAccountNativeSegwitIndexZeroSignerNullable();
const { currency = 'STX' } = useParams();

const fundCryptoCurrencyMap: Record<CryptoCurrencies, FundCryptoCurrencyInfo> = {
const fundCryptoCurrencyMap: Record<CryptoCurrency, FundCryptoCurrencyInfo> = {
BTC: {
address: bitcoinSigner?.address,
blockchain: 'bitcoin',
Expand All @@ -46,8 +46,7 @@ export function FundPage() {
},
};

const { address, blockchain, route, symbol } =
fundCryptoCurrencyMap[currency as CryptoCurrencies];
const { address, blockchain, route, symbol } = fundCryptoCurrencyMap[currency as CryptoCurrency];

if (!address) return <FullPageLoadingSpinner />;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { HStack, Stack, styled } from 'leather-styles/jsx';
import get from 'lodash.get';

import { decodeBitcoinTx } from '@leather.io/bitcoin';
import type { CryptoCurrencies } from '@leather.io/models';
import type { CryptoCurrency } from '@leather.io/models';
import {
useBitcoinBroadcastTransaction,
useCryptoCurrencyMarketDataMeanAverage,
Expand Down Expand Up @@ -34,7 +34,7 @@ import { useCurrentAccountNativeSegwitAddressIndexZero } from '@app/store/accoun
import { SendTransferConfirmationDetails } from './components/send-transfer-confirmation-details';
import { useRpcSendTransferRequestParams } from './use-rpc-send-transfer';

const symbol: CryptoCurrencies = 'BTC';
const symbol: CryptoCurrency = 'BTC';

function useRpcSendTransferConfirmationState() {
const location = useLocation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Stack } from 'leather-styles/jsx';
import get from 'lodash.get';

import { decodeBitcoinTx } from '@leather.io/bitcoin';
import type { CryptoCurrencies } from '@leather.io/models';
import type { CryptoCurrency } from '@leather.io/models';
import {
useBitcoinBroadcastTransaction,
useCryptoCurrencyMarketDataMeanAverage,
Expand Down Expand Up @@ -40,7 +40,7 @@ import { useCurrentNativeSegwitUtxos } from '@app/query/bitcoin/address/utxos-by

import { useSendFormNavigate } from '../../hooks/use-send-form-navigate';

const symbol: CryptoCurrencies = 'BTC';
const symbol: CryptoCurrency = 'BTC';

function useBtcSendFormConfirmationState() {
const location = useLocation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SendCryptoAssetSelectors } from '@tests/selectors/send.selectors';
import { Form, Formik } from 'formik';
import { Box } from 'leather-styles/jsx';

import type { CryptoCurrencies } from '@leather.io/models';
import type { CryptoCurrency } from '@leather.io/models';
import { useCryptoCurrencyMarketDataMeanAverage } from '@leather.io/query';
import { BtcAvatarIcon, Button, Callout, Link } from '@leather.io/ui';
import { formatMoney } from '@leather.io/utils';
Expand All @@ -21,7 +21,7 @@ import { useSendFormRouteState } from '../../hooks/use-send-form-route-state';
import { createDefaultInitialFormValues, defaultSendFormFormikProps } from '../../send-form.utils';
import { useBtcSendForm } from './use-btc-send-form';

const symbol: CryptoCurrencies = 'BTC';
const symbol: CryptoCurrency = 'BTC';

export function BtcSendForm() {
const routeState = useSendFormRouteState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Outlet, useParams } from 'react-router-dom';
import { deserializeTransaction } from '@stacks/transactions';
import { Box, Stack } from 'leather-styles/jsx';

import type { CryptoCurrencies } from '@leather.io/models';
import type { CryptoCurrency } from '@leather.io/models';
import { InfoCircleIcon } from '@leather.io/ui';

import { useLocationStateWithCache } from '@app/common/hooks/use-location-state';
Expand All @@ -29,14 +29,14 @@ export function StacksSendFormConfirmation() {
const { symbol = 'STX' } = useParams();

const { stacksBroadcastTransaction, isBroadcasting } = useStacksBroadcastTransaction({
token: symbol.toUpperCase() as CryptoCurrencies,
token: symbol.toUpperCase() as CryptoCurrency,
decimals,
});

const stacksDeserializedTransaction = deserializeTransaction(tx);

const { formReviewTxSummary } = useStacksTransactionSummary(
symbol.toUpperCase() as CryptoCurrencies
symbol.toUpperCase() as CryptoCurrency
);
const {
txValue,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CryptoCurrencies } from '@leather.io/models';
import type { CryptoCurrency } from '@leather.io/models';
import { useCryptoCurrencyMarketDataMeanAverage } from '@leather.io/query';
import { StxAvatarIcon } from '@leather.io/ui';

Expand All @@ -12,7 +12,7 @@ import { SendMaxButton } from '../../components/send-max-button';
import { StacksCommonSendForm } from '../stacks/stacks-common-send-form';
import { useStxSendForm } from './use-stx-send-form';

const symbol = 'STX' satisfies CryptoCurrencies;
const symbol = 'STX' satisfies CryptoCurrency;

export function StxSendForm() {
const stxMarketData = useCryptoCurrencyMarketDataMeanAverage(symbol);
Expand Down

0 comments on commit 54e2865

Please sign in to comment.