Skip to content

Commit

Permalink
feat: support testnet 4, closes LEA-1406
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Oct 17, 2024
1 parent 1df5138 commit 395223e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
25 changes: 18 additions & 7 deletions src/app/features/add-network/network-form-fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { HStack, styled } from 'leather-styles/jsx';

import {
BITCOIN_API_BASE_URL_MAINNET,
BITCOIN_API_BASE_URL_TESTNET,
BITCOIN_API_BASE_URL_TESTNET3,

Check failure on line 9 in src/app/features/add-network/network-form-fields.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'"@leather.io/models"' has no exported member named 'BITCOIN_API_BASE_URL_TESTNET3'. Did you mean 'BITCOIN_API_BASE_URL_TESTNET'?
BITCOIN_API_BASE_URL_TESTNET4,

Check failure on line 10 in src/app/features/add-network/network-form-fields.tsx

View workflow job for this annotation

GitHub Actions / typecheck

'"@leather.io/models"' has no exported member named 'BITCOIN_API_BASE_URL_TESTNET4'. Did you mean 'BITCOIN_API_BASE_URL_TESTNET'?
type BitcoinNetwork,

Check failure on line 11 in src/app/features/add-network/network-form-fields.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Module '"@leather.io/models"' has no exported member 'BitcoinNetwork'.
type BitcoinNetworkModes,
} from '@leather.io/models';
import {
Expand All @@ -24,15 +26,19 @@ import { type AddNetworkFormValues } from './use-add-network';

const networks: {
label: string;
value: BitcoinNetworkModes;
value: BitcoinNetwork;
}[] = [
{
label: 'Mainnet',
value: 'mainnet',
},
{
label: 'Testnet',
value: 'testnet',
label: 'Testnet3',
value: 'testnet3',
},
{
label: 'Testnet4',
value: 'testnet4',
},
{
label: 'Signet',
Expand Down Expand Up @@ -66,15 +72,20 @@ export function NetworkFormFields({ isEditNetworkMode }: NetworkFormFieldsProps)
[setFieldValue]
);

function setNetworkUrls(value: BitcoinNetworkModes) {
function setNetworkUrls(value: BitcoinNetwork | BitcoinNetworkModes) {
switch (value) {
case 'mainnet':
setStacksUrl('https://api.hiro.so');
setBitcoinUrl(BITCOIN_API_BASE_URL_MAINNET);
break;
case 'testnet':
case 'testnet3':
setStacksUrl('https://api.testnet.hiro.so');
setBitcoinUrl(BITCOIN_API_BASE_URL_TESTNET3);
break;
case 'testnet4':
setStacksUrl('https://api.testnet.hiro.so');
setBitcoinUrl(BITCOIN_API_BASE_URL_TESTNET);
setBitcoinUrl(BITCOIN_API_BASE_URL_TESTNET4);
break;
case 'signet':
setStacksUrl('https://api.testnet.hiro.so');
Expand Down Expand Up @@ -112,7 +123,7 @@ export function NetworkFormFields({ isEditNetworkMode }: NetworkFormFieldsProps)

<Select.Root
defaultValue={initialValues.bitcoinNetwork || networks[0].value}
onValueChange={(value: BitcoinNetworkModes) => {
onValueChange={(value: BitcoinNetwork) => {
setNetworkUrls(value);
void setFieldValue('bitcoinNetwork', value);
}}
Expand Down
6 changes: 3 additions & 3 deletions src/app/store/networks/networks.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ChainID } from '@stacks/transactions';

import {
BITCOIN_API_BASE_URL_MAINNET,
BITCOIN_API_BASE_URL_TESTNET,
BITCOIN_API_BASE_URL_TESTNET3,

Check failure on line 5 in src/app/store/networks/networks.utils.ts

View workflow job for this annotation

GitHub Actions / typecheck

'"@leather.io/models"' has no exported member named 'BITCOIN_API_BASE_URL_TESTNET3'. Did you mean 'BITCOIN_API_BASE_URL_TESTNET'?
type NetworkConfiguration,
} from '@leather.io/models';

Expand Down Expand Up @@ -54,7 +54,7 @@ function checkBitcoinNetworkProperties(
bitcoinUrl:
network.chainId === ChainID.Mainnet
? BITCOIN_API_BASE_URL_MAINNET
: BITCOIN_API_BASE_URL_TESTNET,
: BITCOIN_API_BASE_URL_TESTNET3,
};
} else {
return network;
Expand Down Expand Up @@ -86,7 +86,7 @@ export function transformNetworkStateToMultichainStucture(
bitcoin: {
blockchain: 'bitcoin',
bitcoinNetwork: bitcoinNetwork ? bitcoinNetwork : 'testnet',
bitcoinUrl: bitcoinUrl ? bitcoinUrl : BITCOIN_API_BASE_URL_TESTNET,
bitcoinUrl: bitcoinUrl ? bitcoinUrl : BITCOIN_API_BASE_URL_TESTNET3,
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions tests/mocks/mock-utxos.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Page } from '@playwright/test';

import { BITCOIN_API_BASE_URL_TESTNET } from '@leather.io/models';
import { BITCOIN_API_BASE_URL_TESTNET3 } from '@leather.io/models';

Check failure on line 3 in tests/mocks/mock-utxos.ts

View workflow job for this annotation

GitHub Actions / typecheck

'"@leather.io/models"' has no exported member named 'BITCOIN_API_BASE_URL_TESTNET3'. Did you mean 'BITCOIN_API_BASE_URL_TESTNET'?

import { TEST_ACCOUNT_1_NATIVE_SEGWIT_ADDRESS } from './constants';

Expand Down Expand Up @@ -133,7 +133,7 @@ export async function mockMainnetTestAccountBitcoinRequests(page: Page) {
}

export async function mockTestnetTestAccountEmptyUtxosRequests(page: Page) {
await page.route(`${BITCOIN_API_BASE_URL_TESTNET}/address/**/utxo`, route =>
await page.route(`${BITCOIN_API_BASE_URL_TESTNET3}/address/**/utxo`, route =>
route.fulfill({
json: [],
})
Expand Down
4 changes: 2 additions & 2 deletions tests/specs/network/add-network.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NetworkSelectors } from '@tests/selectors/network.selectors';
import { SettingsSelectors } from '@tests/selectors/settings.selectors';

import { BITCOIN_API_BASE_URL_TESTNET } from '@leather.io/models';
import { BITCOIN_API_BASE_URL_TESTNET3 } from '@leather.io/models';

Check failure on line 4 in tests/specs/network/add-network.spec.ts

View workflow job for this annotation

GitHub Actions / typecheck

'"@leather.io/models"' has no exported member named 'BITCOIN_API_BASE_URL_TESTNET3'. Did you mean 'BITCOIN_API_BASE_URL_TESTNET'?

import { test } from '../../fixtures/fixtures';

Expand All @@ -23,7 +23,7 @@ test.describe('Networks tests', () => {

const bitcoinUrl = page.getByTestId(NetworkSelectors.NetworkBitcoinAddress);

test.expect(await bitcoinUrl.inputValue()).toEqual(BITCOIN_API_BASE_URL_TESTNET);
test.expect(await bitcoinUrl.inputValue()).toEqual(BITCOIN_API_BASE_URL_TESTNET3);
});

test('validation error when stacks api url is empty', async ({ networkPage }) => {
Expand Down

0 comments on commit 395223e

Please sign in to comment.