### Install Dependencies and Run Development Server (Yarn)
Source: https://github.com/bitpay/bitpay-app/blob/master/README.md
This snippet outlines the initial steps to set up the development environment for the BitPay App v2. It includes installing project dependencies using Yarn and starting the development server.
```bash
yarn install
yarn start
```
--------------------------------
### Build and Deploy to Android Simulator or Device (Yarn)
Source: https://github.com/bitpay/bitpay-app/blob/master/README.md
Commands to build and deploy the BitPay App v2 to an Android simulator or a physical device using Yarn. Assumes dependencies are installed and the development server is running.
```bash
yarn android
```
--------------------------------
### Build and Deploy to iOS Simulator or Device (Yarn)
Source: https://github.com/bitpay/bitpay-app/blob/master/README.md
Commands to build and deploy the BitPay App v2 to an iOS simulator or a physical device using Yarn. Assumes dependencies are installed and the development server is running.
```bash
yarn ios
yarn ios:device
```
--------------------------------
### Start Cordova to React Native Migration in TypeScript
Source: https://context7.com/bitpay/bitpay-app/llms.txt
Initiates the migration of user data from the legacy Cordova-based BitPay app to the React Native version. This effect handles the automatic migration of keys, wallets, configuration settings, and transaction history.
```typescript
import { startMigration } from './src/store/wallet/effects/import/import';
const dispatch = useAppDispatch();
// Automatically migrates:
// - Keys and wallets
// - Config settings (theme, currency, notifications)
// - Address book contacts
// - Gift card purchase history
// - Buy/swap crypto transaction history
// - Coinbase integration tokens
// - BitPay ID authentication
await dispatch(startMigration());
```
--------------------------------
### Get Buy Crypto Fiat Limits - TypeScript
Source: https://context7.com/bitpay/bitpay-app/llms.txt
Retrieves minimum and maximum purchase limits for buying cryptocurrency through integrated exchanges. It supports specifying an exchange and currency, and also includes a utility to convert USD to other fiat currencies.
```typescript
import { getBuyCryptoFiatLimits, calculateUsdToAltFiat } from './src/store/buy-crypto/buy-crypto.effects';
const dispatch = useAppDispatch();
// Get limits for all exchanges in USD
const limits = dispatch(getBuyCryptoFiatLimits(undefined, 'USD'));
console.log('Buy limits (USD):', limits);
// Buy limits (USD): { min: 50, max: 20000 }
// Get limits for specific exchange (MoonPay) in EUR
const moonpayLimits = dispatch(getBuyCryptoFiatLimits('moonpay', 'EUR'));
console.log('MoonPay limits (EUR):', moonpayLimits);
// MoonPay limits (EUR): { min: 45, max: 18000 }
// Convert USD amount to local currency
const euroAmount = dispatch(calculateUsdToAltFiat(100, 'EUR'));
console.log('100 USD =', euroAmount, 'EUR');
// 100 USD = 92.50 EUR
```
--------------------------------
### Test Deep Linking on Android (npx uri-scheme)
Source: https://github.com/bitpay/bitpay-app/blob/master/README.md
Command to test deep linking functionality on Android using the `npx uri-scheme` tool. It demonstrates how to open a specific URI with parameters, escaping the ampersand for multiple parameters.
```bash
npx uri-scheme open "bitpay://your/deeplink/path?param1=foo1\¶m2=foo2" --android
```
--------------------------------
### Test Deep Linking on iOS (npx uri-scheme)
Source: https://github.com/bitpay/bitpay-app/blob/master/README.md
Command to test deep linking functionality on iOS using the `npx uri-scheme` tool. It demonstrates how to open a specific URI with parameters, escaping the ampersand for multiple parameters.
```bash
npx uri-scheme open "bitpay://your/deeplink/path?params1=foo1\¶m2=foo2" --ios
```
--------------------------------
### Enable Storybook in BitPay App Configuration
Source: https://github.com/bitpay/bitpay-app/blob/master/README.md
This snippet shows how to enable Storybook by modifying a configuration file. After changing the flag, running the app build command will launch Storybook instead of the main application.
```typescript
// src/contants/config.ts
APP_LOAD_STORY_BOOK=true
```
--------------------------------
### Enable Redux Dev Tools in React Native Debugger
Source: https://github.com/bitpay/bitpay-app/blob/master/README.md
Instructions to enable Redux Dev Tools within the React Native Debugger for state management inspection. This involves opening the debugger and selecting the appropriate debug option.
```bash
Tap `D` in the hosting terminal window or shake the device.
Select `Debug with Chrome` (iOS) or `Debug` (Android).
```
--------------------------------
### Convert SSL Certificate to DER format (OpenSSL)
Source: https://github.com/bitpay/bitpay-app/blob/master/README.md
This command uses OpenSSL to convert an existing SSL certificate file (e.g., .crt) into the DER format, which is required for configuring local server access on Android.
```bash
openssl x509 -in your_cert_name.crt -out your_cert_name.der -outform DER
```
--------------------------------
### Android Network Security Configuration for Local Server
Source: https://github.com/bitpay/bitpay-app/blob/master/README.md
An XML snippet for `android/app/src/main/res/xml/network_security_config.xml`. It configures the app to trust a local server certificate and allows connections to a specific local IP address.
```xml
...
123.0.0.7
```
--------------------------------
### Create New HD Key and Wallets (TypeScript)
Source: https://context7.com/bitpay/bitpay-app/llms.txt
Initializes a new hierarchical deterministic (HD) key and creates wallets for specified cryptocurrencies. This function is typically used during the initial onboarding process for new users. It takes an array of currency configurations and a context string as input, returning the created key object.
```typescript
import { startCreateKey } from './src/store/wallet/effects/create/create';
import { useAppDispatch } from './src/utils/hooks';
const dispatch = useAppDispatch();
// Create a new key with Bitcoin and Ethereum wallets
const currencies = [
{ chain: 'btc', currencyAbbreviation: 'btc', isToken: false },
{ chain: 'eth', currencyAbbreviation: 'eth', isToken: false },
{ chain: 'eth', currencyAbbreviation: 'usdc', isToken: true, tokenAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' },
];
try {
const key = await dispatch(startCreateKey(currencies, 'onboarding'));
console.log('Key created:', key.id);
console.log('Wallets:', key.wallets.map(w => w.currencyAbbreviation));
// Key created: abc123-def456-...
// Wallets: ['btc', 'eth', 'usdc']
} catch (error) {
console.error('Failed to create key:', error.message);
}
```
--------------------------------
### Navigate to Buy Crypto Flow - TypeScript
Source: https://context7.com/bitpay/bitpay-app/llms.txt
Initiates the buy crypto flow within the application. This action is typically used to navigate the user to the screen where they can purchase cryptocurrency, and it includes analytics tracking.
```typescript
import { goToBuyCrypto } from './src/store/buy-crypto/buy-crypto.effects';
const dispatch = useAppDispatch();
// Navigate to buy crypto screen
dispatch(goToBuyCrypto());
// Tracks analytics event: "Clicked Buy Crypto" with context "Shortcuts"
// Navigates to BuyAndSell screen with buyCrypto context
```
--------------------------------
### Import from Encrypted Backup File (TypeScript)
Source: https://context7.com/bitpay/bitpay-app/llms.txt
Restores a wallet from an encrypted JSON backup file. This function requires the backup file content and a password for decryption. It utilizes `react-native-fs` for file reading and a `decryptBackup` utility. Requires a dispatch function.
```typescript
import { startImportFile } from './src/store/wallet/effects/import/import';
import RNFS from 'react-native-fs';
const dispatch = useAppDispatch();
// Read and decrypt backup file
const encryptedBackup = await RNFS.readFile('/path/to/backup.json', 'utf8');
const decryptedText = decryptBackup(encryptedBackup, 'user-password');
try {
const key = await dispatch(startImportFile(decryptedText, {
networkName: 'livenet',
}));
console.log('Restored key:', key.id);
console.log('Wallets restored:', key.wallets.length);
} catch (error) {
console.error('Restore failed:', error.message);
}
```
--------------------------------
### Update iOS Info.plist for Custom Deep Link Scheme
Source: https://github.com/bitpay/bitpay-app/blob/master/README.md
Modification required in the `ios/BitPayApp/info.plist` file to register a custom deep link scheme (e.g., `myapp`) with the iOS operating system.
```xml
CFBundleURLSchemes
myapp
```
--------------------------------
### Import from Ledger Hardware Wallet (TypeScript)
Source: https://context7.com/bitpay/bitpay-app/llms.txt
Imports a wallet from a Ledger hardware device for watch-only capability. It uses the extended public key (xPubKey) and specifies account path, coin, chain, derivation strategy, account number, and network. Requires a dispatch function.
```typescript
import { startImportFromHardwareWallet } from './src/store/wallet/effects/import/import';
import { Network } from './src/constants';
const dispatch = useAppDispatch();
try {
const wallet = await dispatch(startImportFromHardwareWallet({
key: hardwareKey, // Hardware wallet key object
hardwareSource: 'ledger',
xPubKey: 'xpub6CUGRUonZSQ4TWtTMmzXdrXDtypWZiD6...',
accountPath: "m/84'/0'/0'", // BIP84 native segwit
coin: 'btc',
chain: 'btc',
derivationStrategy: 'BIP84',
accountNumber: 0,
network: Network.mainnet,
}));
console.log('Hardware wallet imported:', wallet.id);
console.log('Address:', wallet.receiveAddress);
// Hardware wallet imported: hw-ledger-btc-0
// Address: bc1q...
} catch (error) {
console.error('Hardware import failed:', error.message);
}
```
--------------------------------
### Import Wallet from Recovery Phrase (TypeScript)
Source: https://context7.com/bitpay/bitpay-app/llms.txt
Imports an existing wallet using a 12 or 24-word mnemonic recovery phrase. It performs server-assisted discovery to find all associated wallets. Requires a dispatch function and provides options for network, passphrase, and derivation paths.
```typescript
import { startImportMnemonic } from './src/store/wallet/effects/import/import';
import { KeyOptions } from './src/store/wallet/wallet.models';
const dispatch = useAppDispatch();
const importData = {
words: 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
};
const opts: Partial = {
networkName: 'livenet',
passphrase: '', // Optional BIP39 passphrase
useLegacyCoinType: false,
useLegacyPurpose: false,
};
try {
const key = await dispatch(startImportMnemonic(importData, opts));
console.log('Imported key:', key.id);
console.log('Found wallets:', key.wallets.length);
key.wallets.forEach(wallet => {
console.log(`- ${wallet.currencyAbbreviation}: ${wallet.balance?.crypto || 0}`);
});
// Imported key: xyz789-...
// Found wallets: 5
// - btc: 0.5
// - eth: 2.3
// - usdc: 1000
} catch (error) {
if (error.message === 'WALLET_DOES_NOT_EXIST') {
console.log('No existing wallets found for this mnemonic');
} else {
console.error('Import failed:', error.message);
}
}
```
--------------------------------
### Navigate to Swap Crypto Flow - TypeScript
Source: https://context7.com/bitpay/bitpay-app/llms.txt
Initiates the cryptocurrency swap flow, allowing users to exchange one token for another. This function is used to navigate the user to the token swap interface and includes analytics tracking.
```typescript
import { goToSwapCrypto } from './src/store/swap-crypto/swap-crypto.effects';
const dispatch = useAppDispatch();
// Navigate to swap crypto screen
dispatch(goToSwapCrypto());
// Tracks analytics event: "Clicked Swap Crypto" with context "Shortcuts"
// Navigates to SwapCryptoRoot screen
```
--------------------------------
### Modify Deep Link Prefix in BitPay App Configuration (TypeScript)
Source: https://github.com/bitpay/bitpay-app/blob/master/README.md
Configuration change in `src/constants/config.ts` to modify the default deep linking prefix from `bitpay://` to a custom one, like `myapp://`.
```typescript
// src/constants/config.ts
APP_DEEPLINK_PREFIX = "myapp://"
```
--------------------------------
### Update Android Manifest for Custom Deep Link Scheme
Source: https://github.com/bitpay/bitpay-app/blob/master/README.md
Modification required in `android/app/src/main/AndroidManifest.xml` to register a custom deep link scheme (e.g., `myapp`) within the app's intent filters.
```xml
...
```
--------------------------------
### Refresh All Wallets - TypeScript
Source: https://context7.com/bitpay/bitpay-app/llms.txt
Performs a batch update for all wallets across all keys, including rate conversions. This is useful for scenarios like pull-to-refresh to ensure all wallet data is synchronized.
```typescript
import { startUpdateAllKeyAndWalletStatus } from './src/store/wallet/effects/status/status';
const dispatch = useAppDispatch();
await dispatch(startUpdateAllKeyAndWalletStatus({
context: 'pullToRefresh',
force: true,
}));
// Updates all wallet balances and triggers rate refresh
```
--------------------------------
### Wallet Redux Actions - TypeScript
Source: https://context7.com/bitpay/bitpay-app/llms.txt
Key Redux actions for managing the wallet state within the application. These actions handle the creation of keys, adding wallets, updating keys, deleting keys, and setting wallet terms acceptance.
```typescript
import {
successCreateKey,
successAddWallet,
successUpdateKey,
deleteKey,
setWalletTermsAccepted,
} from './src/store/wallet/wallet.actions';
const dispatch = useAppDispatch();
// After creating a new key
dispatch(successCreateKey({ key: newKey }));
// After adding a wallet to existing key
dispatch(successAddWallet({ key: updatedKey }));
// Delete a key and all associated wallets
dispatch(deleteKey({ keyId: 'key-to-delete' }));
// Mark wallet terms as accepted
dispatch(setWalletTermsAccepted());
```
--------------------------------
### Generate Receive Address (TypeScript)
Source: https://context7.com/bitpay/bitpay-app/llms.txt
Creates a new receiving address for a specified wallet. This function supports both single-address chains (like ETH) and multi-address chains (like BTC). It requires a dispatch function and wallet object.
```typescript
import { createWalletAddress } from './src/store/wallet/effects/address/address';
const dispatch = useAppDispatch();
// Generate new address for Bitcoin wallet
const newAddress = await dispatch(createWalletAddress({
wallet: btcWallet,
newAddress: true,
}));
console.log('New receive address:', newAddress);
// New receive address: bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh
```
--------------------------------
### Normalize Mnemonic Phrases in TypeScript
Source: https://context7.com/bitpay/bitpay-app/llms.txt
Standardizes mnemonic phrases by cleaning up whitespace and supporting various languages, including Japanese. This function ensures consistent formatting for recovery phrases, regardless of input variations.
```typescript
import { normalizeMnemonic } from './src/store/wallet/effects/import/import';
// English mnemonic
const normalized = normalizeMnemonic(' abandon abandon abandon ');
console.log(normalized);
// 'abandon abandon abandon'
// Japanese mnemonic (uses ideographic space \u3000)
const japaneseNormalized = normalizeMnemonic('あいこくしん\u3000あいさつ\u3000あいだ');
console.log(japaneseNormalized);
// 'あいこくしん あいさつ あいだ' (preserved ideographic spaces)
```
--------------------------------
### Define Wallet Data Models in TypeScript
Source: https://context7.com/bitpay/bitpay-app/llms.txt
Defines core TypeScript interfaces for representing keys, wallets, and tokens within the BitPay application. These interfaces structure the data for cryptocurrency wallets, including details like currency, balance, and associated tokens.
```typescript
import { Key, Wallet, KeyOptions, Token } from './src/store/wallet/wallet.models';
import { Network } from './src/constants';
// Key represents an HD master key with multiple wallets
interface Key {
id: string;
wallets: Wallet[];
properties: KeyProperties;
methods: KeyMethods;
backupComplete: boolean;
keyName?: string;
isPrivKeyEncrypted?: boolean;
}
// Wallet represents a single cryptocurrency wallet
interface Wallet {
id: string;
currencyAbbreviation: string;
currencyName: string;
chain: string;
network: Network;
balance: {
crypto: string;
cryptoLocked: string;
fiat: string;
fiatLocked: string;
};
receiveAddress?: string;
tokens?: string[]; // Associated token wallet IDs
credentials: WalletCredentials;
isHardwareWallet?: boolean;
}
// Token represents ERC-20/SPL token metadata
interface Token {
symbol: string;
name: string;
decimals: number;
address: string;
}
```
--------------------------------
### Send Transaction Flow (TypeScript)
Source: https://context7.com/bitpay/bitpay-app/llms.txt
Manages the process of sending a cryptocurrency transaction, involving creating a transaction proposal and then publishing and signing it. This is a two-step asynchronous process requiring wallet and key information.
```typescript
import { createTxProposal, publishAndSign } from './src/store/wallet/effects/send/send';
const dispatch = useAppDispatch();
// Step 1: Create transaction proposal
const txp = await dispatch(createTxProposal({
wallet: btcWallet,
recipient: {
address: 'bc1qrecipient...',
amount: 100000, // In satoshis (0.001 BTC)
},
feeLevel: 'normal', // 'superEconomy', 'economy', 'normal', 'priority', 'urgent'
dryRun: false,
}));
console.log('Transaction proposal created:', txp.id);
console.log('Fee:', txp.fee, 'satoshis');
console.log('Total:', txp.amount + txp.fee, 'satoshis');
// Step 2: Publish and sign the transaction
const broadcastedTx = await dispatch(publishAndSign({
txp,
wallet: btcWallet,
key: walletKey,
}));
console.log('Transaction broadcasted:', broadcastedTx.txid);
// Transaction broadcasted: a1b2c3d4e5f6...
```
--------------------------------
### Auto-Detect ERC-20/SPL Tokens - TypeScript
Source: https://context7.com/bitpay/bitpay-app/llms.txt
Automatically detects and creates wallet entries for ERC-20 (Ethereum, Polygon) and SPL (Solana) tokens that have non-zero balances. It utilizes the Moralis API and allows for specifying the key, chain, and optionally a specific token address.
```typescript
import { detectAndCreateTokensForEachEvmWallet } from './src/store/wallet/effects/create/create';
const dispatch = useAppDispatch();
// Detect all tokens for a key
await dispatch(detectAndCreateTokensForEachEvmWallet({
key: existingKey,
force: true, // Force refresh even if recently checked
}));
// Detect tokens for specific chain
await dispatch(detectAndCreateTokensForEachEvmWallet({
key: existingKey,
chain: 'eth', // Only check Ethereum wallets
}));
// Add specific token by address
await dispatch(detectAndCreateTokensForEachEvmWallet({
key: existingKey,
chain: 'matic',
tokenAddress: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619', // WETH on Polygon
}));
```
--------------------------------
### Add New Wallet to Existing Key (TypeScript)
Source: https://context7.com/bitpay/bitpay-app/llms.txt
Adds a new cryptocurrency wallet to an existing key. This function supports adding both native coins and ERC-20/SPL tokens. It requires an existing `Key` object, currency details, and optional configuration options. The function returns the newly created `Wallet` object.
```typescript
import { addWallet, AddWalletData } from './src/store/wallet/effects/create/create';
import { Key, Wallet } from './src/store/wallet/wallet.models';
const dispatch = useAppDispatch();
// Add a Polygon MATIC wallet to existing key
const walletData: AddWalletData = {
key: existingKey, // Previously created Key object
currency: {
chain: 'matic',
currencyAbbreviation: 'matic',
isToken: false,
},
options: {
network: 'livenet',
useNativeSegwit: false,
},
context: 'addWallet',
};
try {
const newWallet: Wallet = await dispatch(addWallet(walletData));
console.log('Wallet added:', newWallet.id);
console.log('Receive address:', newWallet.receiveAddress);
// Wallet added: key123-matic-0
// Receive address: 0x1234...abcd
} catch (error) {
console.error('Failed to add wallet:', error.message);
}
// Add an ERC-20 token (USDT on Ethereum)
const tokenWalletData: AddWalletData = {
key: existingKey,
currency: {
chain: 'eth',
currencyAbbreviation: 'usdt',
isToken: true,
tokenAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7',
decimals: 6,
},
associatedWallet: ethWallet, // Parent ETH wallet
options: {
network: 'livenet',
},
enableCustomTokens: true,
};
const tokenWallet = await dispatch(addWallet(tokenWalletData));
```
--------------------------------
### Refresh Wallet Balance - TypeScript
Source: https://context7.com/bitpay/bitpay-app/llms.txt
Refreshes the balance and transaction status for a specific wallet. This function is essential for ensuring that the displayed wallet information is up-to-date and can be triggered with a force option to bypass cache.
```typescript
import { startUpdateWalletStatus } from './src/store/wallet/effects/status/status';
const dispatch = useAppDispatch();
await dispatch(startUpdateWalletStatus({
key: walletKey,
wallet: btcWallet,
force: true, // Force refresh from server
}));
console.log('Updated balance:', btcWallet.balance);
// Updated balance: { crypto: '0.5 BTC', cryptoLocked: '0', fiat: '$25,000', fiatLocked: '$0' }
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.