Skip to content

Commit

Permalink
Merge pull request #5530 from leather-wallet/release/testnet-support
Browse files Browse the repository at this point in the history
Release/testnet support
  • Loading branch information
fbwoolf authored Jun 17, 2024
2 parents eaafbaa + 22f727e commit bcd3d64
Show file tree
Hide file tree
Showing 347 changed files with 1,215 additions and 4,302 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/create-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ jobs:
from_branch: main
target_branch: dev
message: 'chore: post-release merge back'
github_token: ${{ secrets.SEMANTIC_RELEASE_TOKEN }}
github_token: ${{ secrets.LEATHER_BOT }}
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,13 @@
"@dlc-link/dlc-tools": "1.1.1",
"@fungible-systems/zone-file": "2.0.0",
"@hirosystems/token-metadata-api-client": "1.2.0",
"@leather-wallet/bitcoin": "0.6.9",
"@leather-wallet/models": "0.6.8",
"@leather-wallet/query": "0.6.12",
"@leather-wallet/bitcoin": "0.7.2",
"@leather-wallet/constants": "0.6.3",
"@leather-wallet/crypto": "1.0.1",
"@leather-wallet/models": "0.8.0",
"@leather-wallet/query": "0.8.6",
"@leather-wallet/tokens": "0.5.2",
"@leather-wallet/utils": "0.7.0",
"@leather-wallet/utils": "0.8.1",
"@ledgerhq/hw-transport-webusb": "6.27.19",
"@noble/hashes": "1.4.0",
"@noble/secp256k1": "2.1.0",
Expand Down Expand Up @@ -204,7 +206,6 @@
"dompurify": "3.1.4",
"dotenv": "16.4.5",
"ecdsa-sig-formatter": "1.0.11",
"ecpair": "2.1.0",
"formik": "2.4.5",
"jotai": "2.2.1",
"jotai-redux": "0.2.1",
Expand Down Expand Up @@ -255,8 +256,8 @@
"@btckit/types": "0.0.19",
"@chromatic-com/storybook": "1.2.23",
"@leather-wallet/panda-preset": "0.2.0",
"@leather-wallet/prettier-config": "0.4.0",
"@leather-wallet/rpc": "1.0.1",
"@leather-wallet/prettier-config": "0.4.1",
"@leather-wallet/rpc": "1.0.3",
"@ls-lint/ls-lint": "2.2.3",
"@mdx-js/loader": "3.0.0",
"@pandacss/dev": "0.40.1",
Expand All @@ -268,7 +269,7 @@
"@sentry/react": "7.106.0",
"@sentry/webpack-plugin": "2.17.0",
"@stacks/connect-react": "22.2.0",
"@stacks/stacks-blockchain-api-types": "6.3.4",
"@stacks/stacks-blockchain-api-types": "7.8.2",
"@storybook/addon-docs": "8.0.1",
"@storybook/addon-essentials": "8.0.1",
"@storybook/addon-interactions": "8.0.1",
Expand Down Expand Up @@ -360,6 +361,7 @@
"webpack-shell-plugin": "0.5.0"
},
"resolutions": {
"braces": "3.0.3",
"nanoid": "3.3.4",
"socket.io-parser": "4.2.4",
"wrap-ansi": "7.0.0",
Expand Down
484 changes: 266 additions & 218 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/app/app.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Suspense } from 'react';
import { Provider as ReduxProvider } from 'react-redux';

import { LeatherQueryProvider } from '@leather-wallet/query';
import { QueryClientProvider } from '@tanstack/react-query';
import { PersistGate } from 'redux-persist/integration/react';

import { LeatherQueryProvider } from '@leather-wallet/query';

import { GITHUB_ORG, GITHUB_REPO } from '@shared/constants';
import { BRANCH_NAME, WALLET_ENVIRONMENT } from '@shared/environment';

Expand All @@ -25,6 +26,7 @@ const reactQueryDevToolsEnabled = process.env.REACT_QUERY_DEVTOOLS_ENABLED === '

function ConnectedApp() {
const network = useCurrentNetwork();

return (
<QueryClientProvider client={queryClient}>
<LeatherQueryProvider
Expand Down
44 changes: 0 additions & 44 deletions src/app/common/api/fetch-wrapper.ts

This file was deleted.

19 changes: 0 additions & 19 deletions src/app/common/asset-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,6 @@ import {
isMoneyGreaterThanZero,
} from '@leather-wallet/utils';

export function sortAssetsByName<T extends { name: string }[]>(assets: T) {
return assets
.sort((a, b) => {
if (a.name < b.name) return -1;
if (a.name > b.name) return 1;
return 0;
})
.sort((a, b) => {
if (a.name === 'STX') return -1;
if (b.name !== 'STX') return 1;
return 0;
})
.sort((a, b) => {
if (a.name === 'BTC') return -1;
if (b.name !== 'BTC') return 1;
return 0;
});
}

export function migratePositiveAssetBalancesToTop<T extends { balance: Money }[]>(assets: T) {
const assetsWithPositiveBalance = assets.filter(asset => asset.balance.amount.isGreaterThan(0));
const assetsWithZeroBalance = assets.filter(asset => asset.balance.amount.isEqualTo(0));
Expand Down
3 changes: 2 additions & 1 deletion src/app/common/authentication/use-finish-auth-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import {
updateWalletConfigWithApp,
} from '@stacks/wallet-sdk';

import { gaiaUrl } from '@leather-wallet/constants';

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

import { useAuthRequestParams } from '@app/common/hooks/auth/use-auth-request-params';
Expand Down
9 changes: 4 additions & 5 deletions src/app/common/hooks/account/use-account-names.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
import { useMemo } from 'react';

import { useGetBnsNamesOwnedByAddressQuery } from '@leather-wallet/query';
import { isUndefined } from '@leather-wallet/utils';

import { parseIfValidPunycode } from '@app/common/utils';
import { formatAccountName } from '@app/common/utils/format-account-name';
import { getAutogeneratedAccountDisplayName } from '@app/common/utils/get-account-display-name';
import { useCurrentAccountNames } from '@app/query/stacks/bns/bns.hooks';
import { useGetBnsNamesOwnedByAddress } from '@app/query/stacks/bns/bns.query';
import { useCurrentStacksAccount } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks';

export function useCurrentAccountDisplayName() {
const account = useCurrentStacksAccount();
const { data: names = [] } = useCurrentAccountNames();
const names = useGetBnsNamesOwnedByAddressQuery(account?.address ?? '').data?.names;

return useMemo(() => {
if (isUndefined(account?.index) && (!account || typeof account?.index !== 'number'))
return 'Account';
if (names[0]) return parseIfValidPunycode(names[0]);
if (names?.length && names[0]) return parseIfValidPunycode(names[0]);
return getAutogeneratedAccountDisplayName(account?.index);
}, [account, names]);
}

export function useAccountDisplayName({ address, index }: { index: number; address: string }) {
const query = useGetBnsNamesOwnedByAddress(address, {
const query = useGetBnsNamesOwnedByAddressQuery(address, {
select: resp => {
const names = resp.names ?? [];
return formatAccountName(names[0]) || getAutogeneratedAccountDisplayName(index);
Expand Down
6 changes: 4 additions & 2 deletions src/app/common/hooks/account/use-refresh-all-account-data.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { useCallback } from 'react';

import { useAccountMempoolQuery } from '@leather-wallet/query';
import { delay } from '@leather-wallet/utils';

import { useCurrentAccountMempool } from '@app/query/stacks/mempool/mempool.hooks';
import { useCurrentStacksAccountAddress } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks';

// TODO: Can this be removed? It seems like we should be able
// to use react-query itself to do this if needed?
export function useRefreshAllAccountData() {
const { refetch } = useCurrentAccountMempool();
const address = useCurrentStacksAccountAddress();
const { refetch } = useAccountMempoolQuery(address);
return useCallback(
async (ms?: number) => {
if (typeof ms === 'number') await delay(ms);
Expand Down
8 changes: 6 additions & 2 deletions src/app/common/hooks/analytics/use-analytics.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { useEffect, useMemo } from 'react';

import type { NetworkConfiguration } from '@leather-wallet/models';
import {
EventParams,
PageParams,
} from '@segment/analytics-next/dist/types/core/arguments-resolver';

import { HIRO_API_BASE_URL_MAINNET, HIRO_API_BASE_URL_TESTNET } from '@shared/constants';
import {
HIRO_API_BASE_URL_MAINNET,
HIRO_API_BASE_URL_TESTNET,
type NetworkConfiguration,
} from '@leather-wallet/models';

import { IS_TEST_ENV, SEGMENT_WRITE_KEY } from '@shared/environment';
import { logger } from '@shared/logger';
import { analytics, initAnalytics } from '@shared/utils/analytics';
Expand Down
6 changes: 4 additions & 2 deletions src/app/common/hooks/balance/use-total-balance.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { useMemo } from 'react';

import { useCryptoCurrencyMarketDataMeanAverage } from '@leather-wallet/query';
import {
useCryptoCurrencyMarketDataMeanAverage,
useStxCryptoAssetBalance,
} from '@leather-wallet/query';
import { baseCurrencyAmountInQuote, createMoney, i18nFormatCurrency } from '@leather-wallet/utils';

import { useBtcCryptoAssetBalanceNativeSegwit } from '@app/query/bitcoin/balance/btc-balance-native-segwit.hooks';
import { useStxCryptoAssetBalance } from '@app/query/stacks/balance/account-balance.hooks';

interface UseTotalBalanceArgs {
btcAddress: string;
Expand Down
9 changes: 4 additions & 5 deletions src/app/common/hooks/use-bitcoin-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ import { useNavigate } from 'react-router-dom';

import { RpcErrorCode } from '@btckit/types';
import { JsDLCInterface } from '@dlc-link/dlc-tools';
import { bytesToHex } from '@stacks/common';

import { deriveAddressIndexKeychainFromAccount } from '@leather-wallet/bitcoin';
import { extractAddressIndexFromPath } from '@leather-wallet/crypto';
import type { Money } from '@leather-wallet/models';
import {
sendAcceptedBitcoinContractOfferToProtocolWallet,
useCalculateBitcoinFiatValue,
useCryptoCurrencyMarketDataMeanAverage,
} from '@leather-wallet/query';
import { createMoneyFromDecimal, i18nFormatCurrency, satToBtc } from '@leather-wallet/utils';
import { bytesToHex } from '@stacks/common';

import {
deriveAddressIndexKeychainFromAccount,
extractAddressIndexFromPath,
} from '@shared/crypto/bitcoin/bitcoin.utils';
import { RouteUrls } from '@shared/route-urls';
import { BitcoinContractResponseStatus } from '@shared/rpc/methods/accept-bitcoin-contract';
import { makeRpcErrorResponse, makeRpcSuccessResponse } from '@shared/rpc/rpc-methods';
Expand Down
4 changes: 1 addition & 3 deletions src/app/common/hooks/use-convert-to-fiat-amount.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { useCallback } from 'react';

import type { Money } from '@leather-wallet/models';
import type { CryptoCurrencies, Money } from '@leather-wallet/models';
import { useCryptoCurrencyMarketDataMeanAverage } from '@leather-wallet/query';
import { baseCurrencyAmountInQuote } from '@leather-wallet/utils';

import { CryptoCurrencies } from '@shared/models/currencies.model';

export function useConvertCryptoCurrencyToFiatAmount(currency: CryptoCurrencies) {
// TODO: unsafe type assumption
const cryptoCurrencyMarketData = useCryptoCurrencyMarketDataMeanAverage(
Expand Down
2 changes: 1 addition & 1 deletion src/app/common/hooks/use-key-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export function useKeyActions() {
const analytics = useAnalytics();
const dispatch = useAppDispatch();
const defaultKeyDetails = useCurrentKeyDetails();
const stxClient = useStacksClient();
const btcClient = useBitcoinClient();
const stxClient = useStacksClient();

return useMemo(
() => ({
Expand Down
1 change: 0 additions & 1 deletion src/app/common/hooks/use-loading.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useLoadingState } from '@app/store/ui/ui.hooks';

export enum LoadingKeys {
INCREASE_FEE_DRAWER = 'loading/INCREASE_FEE_DRAWER',
SUBMIT_SEND_FORM_TRANSACTION = 'loading/SUBMIT_SEND_FORM_TRANSACTION',
SUBMIT_SWAP_TRANSACTION = 'loading/SUBMIT_SWAP_TRANSACTION',
SUBMIT_TRANSACTION_REQUEST = 'loading/SUBMIT_TRANSACTION_REQUEST',
Expand Down
3 changes: 2 additions & 1 deletion src/app/common/hooks/use-location-state.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useEffect, useState } from 'react';
import { useLocation } from 'react-router-dom';

import { isUndefined } from '@leather-wallet/utils';
import get from 'lodash.get';

import { isUndefined } from '@leather-wallet/utils';

type LocationState = string | boolean | undefined | number | Location;

export function useLocationState<T extends LocationState>(propName: string): T;
Expand Down
5 changes: 3 additions & 2 deletions src/app/common/hooks/use-submit-stx-transaction.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useCallback } from 'react';

import { delay, isError } from '@leather-wallet/utils';
import { bytesToHex } from '@stacks/common';
import { StacksTransaction, broadcastTransaction } from '@stacks/transactions';

import { delay, isError } from '@leather-wallet/utils';

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

import { getErrorMessage } from '@app/common/get-error-message';
Expand Down Expand Up @@ -50,7 +51,7 @@ export function useSubmitTransactionCallback({ loadingKey }: UseSubmitTransactio
logger.info('Transaction broadcast', response);
submittedTransactionsActions.newTransactionSubmitted({
rawTx: bytesToHex(transaction.serialize()),
txId: safelyFormatHexTxid(response.txid),
txid: safelyFormatHexTxid(response.txid),
});

await delay(500);
Expand Down
3 changes: 2 additions & 1 deletion src/app/common/persistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persi
import { MutationCache, QueryCache, QueryClient } from '@tanstack/react-query';
import { persistQueryClient } from '@tanstack/react-query-persist-client';

import { PERSISTENCE_CACHE_TIME } from '@shared/constants';
import { PERSISTENCE_CACHE_TIME } from '@leather-wallet/constants';

import { IS_TEST_ENV } from '@shared/environment';

import { createAnalytics } from './hooks/analytics/use-analytics';
Expand Down
3 changes: 2 additions & 1 deletion src/app/common/profiles/requests.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { isString } from '@leather-wallet/utils';
import { ProfileUpdatePayload } from '@stacks/connect';
import { getPublicKeyFromPrivate } from '@stacks/encryption';
import { Person } from '@stacks/profile';
import { getAppPrivateKey } from '@stacks/wallet-sdk';
import { TokenVerifier, decodeToken } from 'jsontokens';

import { isString } from '@leather-wallet/utils';

import { StacksAccount } from '@app/store/accounts/blockchain/stacks/stacks-account.models';

export function getProfileDataContentFromToken(requestToken: string): ProfileUpdatePayload {
Expand Down
5 changes: 3 additions & 2 deletions src/app/common/psbt/requests.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { Money } from '@leather-wallet/models';
import { isString } from '@leather-wallet/utils';
import type { TransactionInput } from '@scure/btc-signer/psbt';
import { PsbtPayload } from '@stacks/connect';
import { decodeToken } from 'jsontokens';

import type { Money } from '@leather-wallet/models';
import { isString } from '@leather-wallet/utils';

export interface SignPsbtArgs {
addressNativeSegwitTotal?: Money;
addressTaprootTotal?: Money;
Expand Down
3 changes: 2 additions & 1 deletion src/app/common/signature/requests.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { isString } from '@leather-wallet/utils';
import { CommonSignaturePayload, SignaturePayload } from '@stacks/connect';
import { deserializeCV } from '@stacks/transactions';
import { TokenInterface, decodeToken } from 'jsontokens';

import { isString } from '@leather-wallet/utils';

import { StructuredMessageDataDomain } from '@shared/signature/signature-types';

export function getGenericSignaturePayloadFromToken(requestToken: string): CommonSignaturePayload {
Expand Down
6 changes: 4 additions & 2 deletions src/app/common/stacks-utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { initBigNumber, microStxToStx } from '@leather-wallet/utils';
import { ChainID } from '@stacks/transactions';
import BigNumber from 'bignumber.js';
import { c32addressDecode } from 'c32check';

import { NetworkConfiguration, STX_DECIMALS } from '@shared/constants';
import { STX_DECIMALS } from '@leather-wallet/constants';
import type { NetworkConfiguration } from '@leather-wallet/models';
import { initBigNumber, microStxToStx } from '@leather-wallet/utils';

import { logger } from '@shared/logger';
import { isValidUrl } from '@shared/utils/validate-url';

Expand Down
Loading

0 comments on commit bcd3d64

Please sign in to comment.