-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #256 from yours-org/spv-wallet-browser-merge
Spv wallet browser merge
- Loading branch information
Showing
23 changed files
with
2,559 additions
and
3,491 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Run Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '20' | ||
|
||
- name: Install dependencies | ||
run: yarn install | ||
|
||
- name: Run tests if available | ||
run: | | ||
if [ -n "$(find . -name '*.test.js' -o -name '*.test.ts' -o -name '*.spec.js' -o -name '*.spec.ts')" ]; then | ||
yarn test --passWithNoTests | ||
else | ||
echo "No test files found. Skipping tests." | ||
fi |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import axios from 'axios'; | ||
|
||
const WHATSONCHAIN_API_URL = 'https://api.whatsonchain.com/v1/bsv/test'; | ||
const WITNESSONCHAIN_API_URL = 'https://witnessonchain.com/v1'; | ||
|
||
interface FaucetResponse { | ||
code: number; | ||
message: string; | ||
raw: string; | ||
txid: string; | ||
} | ||
|
||
export async function requestTestnetCoins(address: string): Promise<FaucetResponse> { | ||
try { | ||
const response = await axios.post<FaucetResponse>(`${WITNESSONCHAIN_API_URL}/faucet/tbsv`, { | ||
address, | ||
channel: 'yours-wallet', | ||
}); | ||
return response.data; | ||
} catch (error) { | ||
console.error('Error requesting testnet coins:', error); | ||
throw error; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { useState } from 'react'; | ||
import { Button } from './Button'; | ||
import { useTheme } from '../hooks/useTheme'; | ||
import { requestTestnetCoins } from '../api/faucet'; | ||
import { useSnackbar } from '../hooks/useSnackbar'; | ||
import { ParseMode } from 'spv-store'; | ||
import { Transaction } from '@bsv/sdk'; | ||
import { useServiceContext } from '../hooks/useServiceContext'; | ||
|
||
interface FaucetButtonProps { | ||
address: string; | ||
isTestnet: boolean; | ||
onConfirmation: () => void; | ||
} | ||
|
||
export function FaucetButton({ address, isTestnet, onConfirmation }: FaucetButtonProps) { | ||
const { theme } = useTheme(); | ||
const { addSnackbar } = useSnackbar(); | ||
const { oneSatSPV } = useServiceContext(); | ||
const [isLoading, setIsLoading] = useState(false); | ||
|
||
const handleGetCoins = async () => { | ||
if (!isTestnet) return; | ||
|
||
setIsLoading(true); | ||
|
||
try { | ||
const response = await requestTestnetCoins(address); | ||
|
||
if (response.code === 0) { | ||
const tx = Transaction.fromHex(response.raw); | ||
const res = await oneSatSPV.stores.txos?.ingest(tx, 'faucet', ParseMode.Persist, false); | ||
if (res?.txid) { | ||
onConfirmation(); | ||
} else { | ||
addSnackbar('Transaction sent, but not yet confirmed. Please check your balance later.', 'info'); | ||
} | ||
} else if (response.code === 20) { | ||
throw new Error('Address still in cooldown. Please wait before requesting again.'); | ||
} else { | ||
throw new Error(response.message || 'An unknown error occurred. Please try again later.'); | ||
} | ||
} catch (error) { | ||
const errorMessage = | ||
error instanceof Error ? error.message : 'Failed to get testnet coins. Please try again later.'; | ||
addSnackbar(errorMessage, 'error'); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}; | ||
|
||
if (!isTestnet) return null; | ||
|
||
return ( | ||
<Button | ||
theme={theme} | ||
type="secondary-outline" | ||
label={isLoading ? 'Requesting...' : 'Get Testnet Coins'} | ||
onClick={handleGetCoins} | ||
disabled={isLoading} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.