Skip to content

Commit

Permalink
fix: possible issue introduced with testnet4
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Jan 17, 2025
1 parent 43bd1b2 commit 6adb427
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/app/store/networks/networks.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { ChainID } from '@stacks/transactions';
import {
BITCOIN_API_BASE_URL_MAINNET,
BITCOIN_API_BASE_URL_TESTNET3,
type BitcoinNetwork,
type NetworkConfiguration,
bitcoinNetworkToNetworkMode,
bitcoinNetworks,
} from '@leather.io/models';

import { PersistedNetworkConfiguration } from './networks.slice';
Expand Down Expand Up @@ -64,6 +66,10 @@ function checkBitcoinNetworkProperties(
}
}

function isValidBitcoinNetwork(network: string): network is BitcoinNetwork {
return bitcoinNetworks.includes(network as BitcoinNetwork);
}

export function transformNetworkStateToMultichainStucture(
state: Record<string, PersistedNetworkConfiguration>
) {
Expand All @@ -82,14 +88,16 @@ export function transformNetworkStateToMultichainStucture(
chain: {
stacks: {
blockchain: 'stacks',
url: url,
url,
chainId,
subnetChainId,
},
bitcoin: {
blockchain: 'bitcoin',
bitcoinNetwork: bitcoinNetwork ?? 'testnet',
mode: bitcoinNetworkToNetworkMode(bitcoinNetwork ?? 'testnet'),
bitcoinNetwork: isValidBitcoinNetwork(bitcoinNetwork) ? bitcoinNetwork : 'testnet4',
mode: isValidBitcoinNetwork(bitcoinNetwork)
? bitcoinNetworkToNetworkMode(bitcoinNetwork)
: 'testnet',
bitcoinUrl: bitcoinUrl ?? BITCOIN_API_BASE_URL_TESTNET3,
},
},
Expand Down

0 comments on commit 6adb427

Please sign in to comment.