Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/explorer/src/components/SearchBar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useContext, useRef } from 'react'
import { useNavigate } from 'react-router-dom'
import { ComputerContext } from '@bitcoin-computer/components'
import { isValidHexadecimalPublicKey } from '../utils'
import { isPossibleCryptoAddress, isValidHexadecimalPublicKey } from '../utils'

export function SearchBar() {
const inputRef = useRef<HTMLInputElement>(null)
Expand All @@ -21,6 +21,7 @@ export function SearchBar() {
}
} else if (isValidHexadecimalPublicKey(searchInput))
navigate(`/?public-key=${searchInput.trim()}`)
else if (isPossibleCryptoAddress(searchInput)) navigate(`/utxos/${searchInput}`)
else navigate(`/transactions/${searchInput}`)
}
}
Expand Down
10 changes: 10 additions & 0 deletions packages/explorer/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ export const getValueForType = (type: string, stringValue: string) => {
export const capitalizeFirstLetter = (string: string) =>
string.charAt(0).toUpperCase() + string.slice(1)

export const isPossibleCryptoAddress = (address: string): boolean => {
// Regular expressions for common address formats
const p2pkhRegex = /^[1mn][a-km-zA-HJ-NP-Z1-9]{25,34}$/ // P2PKH (mainnet/testnet)
const p2shRegex = /^[23][a-km-zA-HJ-NP-Z1-9]{25,34}$/ // P2SH (mainnet/testnet)
const bech32Regex = /^(bc1|ltc1|doge1|t[a-z]{2})[a-z0-9]{6,80}$/ // Bech32 (mainnet/testnet)

// Check if the address matches any of the regex patterns
return p2pkhRegex.test(address) || p2shRegex.test(address) || bech32Regex.test(address)
}

export const isValidHexadecimalPublicKey = (publicKey: string): boolean => {
if (!publicKey) return false
const trimmedPublicKey = publicKey.trim()
Expand Down
4 changes: 2 additions & 2 deletions packages/vite-template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"lint:fix": "eslint . --fix",
"preview": "vite preview",
"start": "vite",
"test": "vitest run",
"test": "vitest run && npm run test:puppeteer:build:headless",
"test:dev": "vitest",
"test:puppeteer": "vitest run --config vite.puppeteer.config.ts",
"test:puppeteer": "vitest run --config vitest.puppeteer.config.ts",
"test:puppeteer:headless": "HEADLESS=true npm run test:puppeteer",
"test:puppeteer:build:headless": "npm run build && (npm run preview & sleep 2 && URL=http://localhost:4173 HEADLESS=true npm run test:puppeteer && pkill -f 'vite preview')",
"test:show": "npm run test 2>&1 | tee vite-template-test.log; if [ ${PIPESTATUS[0]} -ne 0 ]; then open vite-template-test.log; fi",
Expand Down
18 changes: 5 additions & 13 deletions packages/vite-template/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/// <reference types="vitest" />
/// <reference types="vite/client" />

import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
const env = loadEnv(mode, process.cwd(), '');
return {
plugins: [react()],
server: {
Expand All @@ -16,11 +14,5 @@ export default defineConfig(({ mode }) => {
'Cross-Origin-Embedder-Policy': 'require-corp',
},
},
test: {
globals: true,
include: ['src/**/*.test.tsx'],
environment: 'jsdom',
setupFiles: ['./src/setupTests.ts'],
},
}
})
};
});
25 changes: 0 additions & 25 deletions packages/vite-template/vite.puppeteer.config.ts

This file was deleted.

25 changes: 25 additions & 0 deletions packages/vite-template/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/// <reference types="vitest" />
/// <reference types="vite/client" />

import { defineConfig } from 'vitest/config'
import baseConfig from './vite.config'
import path from 'path'

export default defineConfig(({ mode }) => {
// Load the base Vite configuration
const base = baseConfig({ mode, command: 'serve' })

return {
...base,
test: {
globals: true,
include: ['src/**/*.test.tsx'],
environment: 'jsdom',
setupFiles: ['./src/setupTests.ts'],
alias: {
// Define the alias pointing to the specific entry point in node_modules
'@bitcoin-computer/lib': path.resolve(__dirname, '../lib/dist/bc-lib.browser.min.mjs'),
},
},
}
})
20 changes: 20 additions & 0 deletions packages/vite-template/vitest.puppeteer.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// <reference types="vitest" />
/// <reference types="vite/client" />

import { defineConfig } from 'vitest/config'
import baseConfig from './vite.config'

// Extend the core Vite configuration with Puppeteer-specific test settings
export default defineConfig(({ mode }) => {
// Load the base Vite configuration
const base = baseConfig({ mode, command: 'serve' })

return {
...base,
test: {
include: ['tests/**/*.test.ts'],
environment: 'node',
testTimeout: 30000,
},
}
})