├── src ├── react-app-env.d.ts ├── setupTests.ts ├── App.test.tsx ├── reportWebVitals.ts ├── index.css ├── index.tsx ├── App.css ├── utils.ts ├── components │ ├── InscribeTransferCard.tsx │ ├── PushTxCard.tsx │ ├── PushPsbtCard.tsx │ ├── SignPsbtCard.tsx │ ├── SendBitcoinCard.tsx │ ├── SendInscriptionCard.tsx │ ├── SendRunesCard.tsx │ └── SignMessageCard.tsx ├── logo.svg ├── const.ts └── App.tsx ├── public ├── robots.txt ├── screen.png ├── favicon.ico ├── logo192.png ├── logo512.png ├── manifest.json └── index.html ├── README.md ├── .gitignore ├── tsconfig.json └── package.json /src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /public/screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dappboris-dev/Fractal-bitcoin-frontend-demo/HEAD/public/screen.png -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dappboris-dev/Fractal-bitcoin-frontend-demo/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dappboris-dev/Fractal-bitcoin-frontend-demo/HEAD/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dappboris-dev/Fractal-bitcoin-frontend-demo/HEAD/public/logo512.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | 3 | React app for demo of using Fractal mainnet and testnet.
4 |

5 | 6 | -------------------------------------------------------------------------------- /src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render, screen } from '@testing-library/react'; 3 | import App from './App'; 4 | 5 | test('renders learn react link', () => { 6 | render(); 7 | const linkElement = screen.getByText(/learn react/i); 8 | expect(linkElement).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /src/reportWebVitals.ts: -------------------------------------------------------------------------------- 1 | import { ReportHandler } from 'web-vitals'; 2 | 3 | const reportWebVitals = (onPerfEntry?: ReportHandler) => { 4 | if (onPerfEntry && onPerfEntry instanceof Function) { 5 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 6 | getCLS(onPerfEntry); 7 | getFID(onPerfEntry); 8 | getFCP(onPerfEntry); 9 | getLCP(onPerfEntry); 10 | getTTFB(onPerfEntry); 11 | }); 12 | } 13 | }; 14 | 15 | export default reportWebVitals; 16 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css2?family=Quicksand:wght@300..700&display=swap'); 2 | 3 | body { 4 | margin: 0; 5 | font-family: -apple-system, BlinkMacSystemFont, "Quicksand", 'Segoe UI', 'Roboto', 'Oxygen', 6 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 7 | sans-serif; 8 | -webkit-font-smoothing: antialiased; 9 | -moz-osx-font-smoothing: grayscale; 10 | } 11 | 12 | 13 | code { 14 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 15 | monospace; 16 | } 17 | -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot( 8 | document.getElementById('root') as HTMLElement 9 | ); 10 | root.render( 11 | 12 | 13 | 14 | ); 15 | 16 | // If you want to start measuring performance in your app, pass a function 17 | // to log results (for example: reportWebVitals(console.log)) 18 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 19 | reportWebVitals(); 20 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "noFallthroughCasesInSwitch": true, 16 | "module": "esnext", 17 | "moduleResolution": "node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "noEmit": true, 21 | "jsx": "react-jsx" 22 | }, 23 | "include": [ 24 | "src" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: start; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/utils.ts: -------------------------------------------------------------------------------- 1 | import BigNumber from "bignumber.js"; 2 | 3 | export function satoshisToAmount(val: number) { 4 | const num = new BigNumber(val); 5 | return num.dividedBy(100000000).toFixed(8); 6 | } 7 | 8 | export function amountToSatoshis(val: any) { 9 | const num = new BigNumber(val); 10 | return num.multipliedBy(100000000).toNumber(); 11 | } 12 | 13 | export const copyToClipboard = (textToCopy: string | number) => { 14 | if (navigator.clipboard && window.isSecureContext) { 15 | return navigator.clipboard.writeText(textToCopy.toString()); 16 | } else { 17 | const textArea = document.createElement("textarea"); 18 | textArea.value = textToCopy.toString(); 19 | textArea.style.position = "absolute"; 20 | textArea.style.opacity = "0"; 21 | textArea.style.left = "-999999px"; 22 | textArea.style.top = "-999999px"; 23 | document.body.appendChild(textArea); 24 | textArea.focus(); 25 | textArea.select(); 26 | return new Promise((res, rej) => { 27 | document.execCommand("copy") ? res() : rej(); 28 | textArea.remove(); 29 | }); 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "unisat-web3-demo", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.5", 7 | "@testing-library/react": "^13.4.0", 8 | "@testing-library/user-event": "^13.5.0", 9 | "@types/jest": "^27.5.2", 10 | "@types/node": "^16.18.14", 11 | "@types/react": "^18.0.28", 12 | "@types/react-dom": "^18.0.11", 13 | "antd": "^5.2.3", 14 | "bignumber.js": "^9.1.2", 15 | "react": "^18.2.0", 16 | "react-dom": "^18.2.0", 17 | "react-scripts": "5.0.1", 18 | "typescript": "^4.9.5", 19 | "web-vitals": "^2.1.4", 20 | "yarn": "^1.22.22" 21 | }, 22 | "scripts": { 23 | "start": "react-scripts start", 24 | "build": "react-scripts build", 25 | "test": "react-scripts test", 26 | "eject": "react-scripts eject" 27 | }, 28 | "eslintConfig": { 29 | "extends": [ 30 | "react-app", 31 | "react-app/jest" 32 | ] 33 | }, 34 | "browserslist": { 35 | "production": [ 36 | ">0.2%", 37 | "not dead", 38 | "not op_mini all" 39 | ], 40 | "development": [ 41 | "last 1 chrome version", 42 | "last 1 firefox version", 43 | "last 1 safari version" 44 | ] 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | Unisat Wallet Demo 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/components/InscribeTransferCard.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useRef, useState } from "react"; 2 | import { Button, Card, Input, Radio } from "antd"; 3 | 4 | export function InscribeTransferCard() { 5 | const [ticker, setTicker] = useState(""); 6 | const [amount, setAmount] = useState(""); 7 | const [result, setResult] = useState({ 8 | success: false, 9 | error: "", 10 | }); 11 | 12 | const doc_url = 13 | "https://docs.unisat.io/dev/unisat-developer-center/unisat-wallet#pushtx"; 14 | 15 | return ( 16 | 17 |
18 |
Docs:
19 | 20 | {doc_url} 21 | 22 |
23 |
24 |
Ticker:
25 | { 28 | setTicker(e.target.value); 29 | }} 30 | > 31 |
32 | 33 |
34 |
Amount:
35 | { 38 | setAmount(e.target.value); 39 | }} 40 | > 41 |
42 | 65 |
66 | ); 67 | } 68 | -------------------------------------------------------------------------------- /src/components/PushTxCard.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useRef, useState } from "react"; 2 | import { Button, Card, Input, Radio } from "antd"; 3 | 4 | export function PushTxCard() { 5 | const [rawtx, setRawtx] = useState(""); 6 | const [result, setResult] = useState({ 7 | success: false, 8 | error: "", 9 | data: "", 10 | }); 11 | 12 | const doc_url = 13 | "https://docs.unisat.io/dev/unisat-developer-center/unisat-wallet#pushtx"; 14 | 15 | return ( 16 | 17 |
18 |
Docs:
19 | 20 | {doc_url} 21 | 22 |
23 | 24 |
25 |
rawtx:
26 | { 29 | setRawtx(e.target.value); 30 | }} 31 | > 32 |
33 | 34 | {result.success ? ( 35 |
36 |
Txid:
37 |
{result.data}
38 |
39 | ) : ( 40 |
41 |
{result.error}
42 |
43 | )} 44 | 45 | 71 |
72 | ); 73 | } 74 | -------------------------------------------------------------------------------- /src/components/PushPsbtCard.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useRef, useState } from "react"; 2 | import { Button, Card, Input, Radio } from "antd"; 3 | 4 | export function PushPsbtCard() { 5 | const [psbtHex, setPsbtHex] = useState(""); 6 | 7 | const [result, setResult] = useState({ 8 | success: false, 9 | error: "", 10 | data: "", 11 | }); 12 | const doc_url = 13 | "https://docs.unisat.io/dev/unisat-developer-center/unisat-wallet#pushtx"; 14 | 15 | return ( 16 | 17 |
18 |
Docs:
19 | 20 | {doc_url} 21 | 22 |
23 | 24 |
25 |
psbt hex:
26 | { 29 | setPsbtHex(e.target.value); 30 | }} 31 | > 32 |
33 | 34 | {result.success ? ( 35 |
36 |
Txid:
37 |
{result.data}
38 |
39 | ) : ( 40 |
41 |
{result.error}
42 |
43 | )} 44 | 45 | 71 |
72 | ); 73 | } 74 | -------------------------------------------------------------------------------- /src/components/SignPsbtCard.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useRef, useState } from "react"; 2 | import { Button, Card, Input, Radio } from "antd"; 3 | 4 | export function SignPsbtCard() { 5 | const [psbtHex, setPsbtHex] = useState(""); 6 | const [psbtResult, setPsbtResult] = useState(""); 7 | const [result, setResult] = useState({ 8 | success: false, 9 | error: "", 10 | data: "", 11 | }); 12 | const doc_url = 13 | "https://docs.unisat.io/dev/unisat-developer-center/unisat-wallet#signpsbt"; 14 | return ( 15 | 16 |
17 |
Docs:
18 | 19 | {doc_url} 20 | 21 |
22 |
23 |
PsbtHex:
24 | { 27 | setPsbtHex(e.target.value); 28 | }} 29 | > 30 |
31 | 32 | {result.success ? ( 33 |
34 |
Result:
35 |
{result.data}
36 |
37 | ) : ( 38 |
39 |
{result.error}
40 |
41 | )} 42 | 43 | 70 |
71 | ); 72 | } 73 | -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/components/SendBitcoinCard.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useRef, useState } from "react"; 2 | import { Button, Card, Input, Radio } from "antd"; 3 | 4 | export function SendBitcoinCard() { 5 | const [toAddress, setToAddress] = useState(""); 6 | const [satoshis, setSatoshis] = useState(1000); 7 | const [result, setResult] = useState({ 8 | success: false, 9 | error: "", 10 | data: "", 11 | }); 12 | const doc_url = 13 | "https://docs.unisat.io/dev/unisat-developer-center/unisat-wallet#sendbitcoin"; 14 | 15 | return ( 16 | 17 |
18 |
Docs:
19 | 20 | {doc_url} 21 | 22 |
23 | 24 |
25 |
Receiver Address:
26 | { 29 | setToAddress(e.target.value); 30 | }} 31 | > 32 |
33 | 34 |
35 |
Amount:
36 | { 39 | setSatoshis(parseInt(e.target.value)); 40 | }} 41 | > 42 |
43 | 44 | {result.success ? ( 45 |
46 |
Txid:
47 |
{result.data}
48 |
49 | ) : ( 50 |
51 |
{result.error}
52 |
53 | )} 54 | 55 | 85 |
86 | ); 87 | } 88 | -------------------------------------------------------------------------------- /src/components/SendInscriptionCard.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useRef, useState } from "react"; 2 | import { Button, Card, Input, Radio } from "antd"; 3 | 4 | export function SendInscriptionCard() { 5 | const [toAddress, setToAddress] = useState(""); 6 | const [inscriptionId, setInscriptionId] = useState(""); 7 | const [result, setResult] = useState({ 8 | success: false, 9 | error: "", 10 | data: "", 11 | }); 12 | const doc_url = 13 | "https://docs.unisat.io/dev/unisat-developer-center/unisat-wallet#sendinscription"; 14 | return ( 15 | 16 |
17 |
Docs:
18 | 19 | {doc_url} 20 | 21 |
22 | 23 |
24 |
Receiver Address:
25 | { 28 | setToAddress(e.target.value); 29 | }} 30 | > 31 |
32 | 33 |
34 |
InscriptionId:
35 | { 38 | setInscriptionId(e.target.value); 39 | }} 40 | > 41 |
42 | 43 | {result.success ? ( 44 |
45 |
Txid:
46 |
{result.data}
47 |
48 | ) : ( 49 |
50 |
{result.error}
51 |
52 | )} 53 | 54 | 84 |
85 | ); 86 | } 87 | -------------------------------------------------------------------------------- /src/components/SendRunesCard.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useRef, useState } from "react"; 2 | import { Button, Card, Input, Radio } from "antd"; 3 | 4 | export function SendRunesCard() { 5 | const [toAddress, setToAddress] = useState(""); 6 | const [runeid, setRuneid] = useState(""); 7 | const [amount, setAmount] = useState(""); 8 | const [result, setResult] = useState({ 9 | success: false, 10 | error: "", 11 | data: "", 12 | }); 13 | const doc_url = 14 | "https://docs.unisat.io/dev/unisat-developer-center/unisat-wallet#sendrunes"; 15 | return ( 16 | 17 |
18 |
Docs:
19 | 20 | {doc_url} 21 | 22 |
23 | 24 |
25 |
Receiver Address:
26 | { 29 | setToAddress(e.target.value); 30 | }} 31 | > 32 |
33 | 34 |
35 |
Runeid:
36 | { 39 | setRuneid(e.target.value); 40 | }} 41 | > 42 |
43 | 44 |
45 |
Amount:
46 | { 49 | setAmount(e.target.value); 50 | }} 51 | > 52 |
53 | 54 | {result.success ? ( 55 |
56 |
Txid:
57 |
{result.data}
58 |
59 | ) : ( 60 |
61 |
{result.error}
62 |
63 | )} 64 | 65 | 96 |
97 | ); 98 | } 99 | -------------------------------------------------------------------------------- /src/components/SignMessageCard.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useRef, useState } from "react"; 2 | import { Button, Card, Input, Radio } from "antd"; 3 | 4 | export function SignMessageCard() { 5 | const [message, setMessage] = useState("hello world~"); 6 | const [result, setResult] = useState({ 7 | success: false, 8 | error: "", 9 | data: "", 10 | }); 11 | const doc_url = 12 | "https://docs.unisat.io/dev/unisat-developer-center/unisat-wallet#signmessage"; 13 | return ( 14 | 15 |
16 |
Docs:
17 | 18 | {doc_url} 19 | 20 |
21 |
22 |
Message:
23 | { 26 | setMessage(e.target.value); 27 | }} 28 | > 29 |
30 | {result.success ? ( 31 |
32 |
Signature:
33 |
{result.data}
34 |
35 | ) : ( 36 |
37 |
{result.error}
38 |
39 | )} 40 | 41 | 67 | 68 | 97 |
98 | ); 99 | } 100 | -------------------------------------------------------------------------------- /src/const.ts: -------------------------------------------------------------------------------- 1 | export enum ChainType { 2 | BITCOIN_MAINNET = "BITCOIN_MAINNET", 3 | BITCOIN_TESTNET = "BITCOIN_TESTNET", 4 | BITCOIN_TESTNET4 = "BITCOIN_TESTNET4", 5 | BITCOIN_SIGNET = "BITCOIN_SIGNET", 6 | FRACTAL_BITCOIN_MAINNET = "FRACTAL_BITCOIN_MAINNET", 7 | FRACTAL_BITCOIN_TESTNET = "FRACTAL_BITCOIN_TESTNET", 8 | } 9 | 10 | export enum NetworkType { 11 | MAINNET, 12 | TESTNET, 13 | } 14 | 15 | type TypeChain = { 16 | enum: ChainType; 17 | label: string; 18 | icon: string; 19 | unit: string; 20 | networkType: NetworkType; 21 | endpoints: string[]; 22 | mempoolSpaceUrl: string; 23 | unisatUrl: string; 24 | ordinalsUrl: string; 25 | }; 26 | 27 | export const CHAINS_MAP: { [key: string]: TypeChain } = { 28 | [ChainType.BITCOIN_MAINNET]: { 29 | enum: ChainType.BITCOIN_MAINNET, 30 | label: "Bitcoin Mainnet", 31 | icon: "./images/artifacts/bitcoin-mainnet.png", 32 | unit: "BTC", 33 | networkType: NetworkType.MAINNET, 34 | endpoints: ["https://wallet-api.unisat.io"], 35 | mempoolSpaceUrl: "https://mempool.space", 36 | unisatUrl: "https://unisat.io", 37 | ordinalsUrl: "https://ordinals.com", 38 | }, 39 | [ChainType.BITCOIN_TESTNET]: { 40 | enum: ChainType.BITCOIN_TESTNET, 41 | label: "Bitcoin Testnet", 42 | icon: "./images/artifacts/bitcoin-testnet.svg", 43 | unit: "tBTC", 44 | networkType: NetworkType.TESTNET, 45 | endpoints: ["https://wallet-api-testnet.unisat.io"], 46 | mempoolSpaceUrl: "https://mempool.space/testnet", 47 | unisatUrl: "https://testnet.unisat.io", 48 | ordinalsUrl: "https://testnet.ordinals.com", 49 | }, 50 | [ChainType.BITCOIN_TESTNET4]: { 51 | enum: ChainType.BITCOIN_TESTNET4, 52 | label: "Bitcoin Testnet4 (Beta)", 53 | icon: "./images/artifacts/bitcoin-testnet.svg", 54 | unit: "tBTC", 55 | networkType: NetworkType.TESTNET, 56 | endpoints: ["https://wallet-api-testnet4.unisat.io"], 57 | mempoolSpaceUrl: "https://mempool.space/testnet4", 58 | unisatUrl: "https://testnet4.unisat.io", 59 | ordinalsUrl: "https://testnet4.ordinals.com", 60 | }, 61 | [ChainType.BITCOIN_SIGNET]: { 62 | enum: ChainType.BITCOIN_SIGNET, 63 | label: "Bitcoin Signet", 64 | icon: "./images/artifacts/bitcoin-signet.svg", 65 | unit: "sBTC", 66 | networkType: NetworkType.TESTNET, 67 | endpoints: ["https://wallet-api-signet.unisat.io"], 68 | mempoolSpaceUrl: "https://mempool.space/signet", 69 | unisatUrl: "https://signet.unisat.io", 70 | ordinalsUrl: "https://signet.ordinals.com", 71 | }, 72 | [ChainType.FRACTAL_BITCOIN_MAINNET]: { 73 | enum: ChainType.FRACTAL_BITCOIN_MAINNET, 74 | label: "Fractal Bitcoin Mainnet", 75 | icon: "./images/artifacts/fractalbitcoin-mainnet.png", 76 | unit: "FB", 77 | networkType: NetworkType.MAINNET, 78 | endpoints: ["https://wallet-api-fractal.unisat.io"], 79 | mempoolSpaceUrl: "https://mempool.fractalbitcoin.io", 80 | unisatUrl: "https://fractal.unisat.io", 81 | ordinalsUrl: "https://ordinals.fractalbitcoin.io", 82 | }, 83 | [ChainType.FRACTAL_BITCOIN_TESTNET]: { 84 | enum: ChainType.FRACTAL_BITCOIN_TESTNET, 85 | label: "Fractal Bitcoin Testnet", 86 | icon: "./images/artifacts/fractalbitcoin-mainnet.png", 87 | unit: "tFB", 88 | networkType: NetworkType.MAINNET, 89 | endpoints: ["https://wallet-api-fractal.unisat.io/testnet"], 90 | mempoolSpaceUrl: "https://mempool-testnet.fractalbitcoin.io", 91 | unisatUrl: "https://fractal-testnet.unisat.io", 92 | ordinalsUrl: "https://ordinals-testnet.fractalbitcoin.io", 93 | }, 94 | }; 95 | -------------------------------------------------------------------------------- /src/App.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useRef, useState } from "react"; 2 | import "./App.css"; 3 | import { Button, Card, CollapseProps, Input, Radio, message } from "antd"; 4 | import { CHAINS_MAP, ChainType } from "./const"; 5 | import { copyToClipboard, satoshisToAmount } from "./utils"; 6 | import { SendBitcoinCard } from "./components/SendBitcoinCard"; 7 | import { PushPsbtCard } from "./components/PushPsbtCard"; 8 | import { PushTxCard } from "./components/PushTxCard"; 9 | import { SignMessageCard } from "./components/SignMessageCard"; 10 | import { SignPsbtCard } from "./components/SignPsbtCard"; 11 | import { Collapse } from "antd"; 12 | import { InscribeTransferCard } from "./components/InscribeTransferCard"; 13 | import { SendInscriptionCard } from "./components/SendInscriptionCard"; 14 | import { SendRunesCard } from "./components/SendRunesCard"; 15 | import useMessage from "antd/es/message/useMessage"; 16 | 17 | function App() { 18 | const [unisatInstalled, setUnisatInstalled] = useState(false); 19 | const [connected, setConnected] = useState(false); 20 | const [accounts, setAccounts] = useState([]); 21 | const [publicKey, setPublicKey] = useState(""); 22 | const [address, setAddress] = useState(""); 23 | const [balance, setBalance] = useState({ 24 | confirmed: 0, 25 | unconfirmed: 0, 26 | total: 0, 27 | }); 28 | const [network, setNetwork] = useState("livenet"); 29 | 30 | const [version, setVersion] = useState(""); 31 | 32 | const [chainType, setChainType] = useState( 33 | ChainType.BITCOIN_MAINNET 34 | ); 35 | 36 | const chain = CHAINS_MAP[chainType]; 37 | 38 | const getBasicInfo = async () => { 39 | const unisat = (window as any).unisat; 40 | 41 | try { 42 | const accounts = await unisat.getAccounts(); 43 | setAccounts(accounts); 44 | } catch (e) { 45 | console.log("getAccounts error", e); 46 | } 47 | 48 | try { 49 | const publicKey = await unisat.getPublicKey(); 50 | setPublicKey(publicKey); 51 | } catch (e) { 52 | console.log("getPublicKey error", e); 53 | } 54 | 55 | try { 56 | const balance = await unisat.getBalance(); 57 | setBalance(balance); 58 | } catch (e) { 59 | console.log("getBalance error", e); 60 | } 61 | 62 | try { 63 | const chain = await unisat.getChain(); 64 | console.log("chain==>",chain); 65 | setChainType(chain.enum); 66 | } catch (e) { 67 | console.log("getChain error", e); 68 | } 69 | 70 | try { 71 | const network = await unisat.getNetwork(); 72 | setNetwork(network); 73 | } catch (e) { 74 | console.log("getNetwork error", e); 75 | } 76 | 77 | try { 78 | const version = await unisat.getVersion(); 79 | setVersion(version); 80 | } catch (e) { 81 | console.log("getVersion error ", e); 82 | } 83 | 84 | if (unisat.getChain !== undefined) { 85 | try { 86 | const chain = await unisat.getChain(); 87 | setChainType(chain.enum); 88 | } catch (e) { 89 | console.log("getChain error", e); 90 | } 91 | } 92 | }; 93 | 94 | const selfRef = useRef<{ accounts: string[] }>({ 95 | accounts: [], 96 | }); 97 | const self = selfRef.current; 98 | const handleAccountsChanged = (_accounts: string[]) => { 99 | console.log("accounts changed", _accounts); 100 | if (self.accounts[0] === _accounts[0]) { 101 | // prevent from triggering twice 102 | return; 103 | } 104 | self.accounts = _accounts; 105 | if (_accounts.length > 0) { 106 | setAccounts(_accounts); 107 | setConnected(true); 108 | 109 | setAddress(_accounts[0]); 110 | 111 | getBasicInfo(); 112 | } else { 113 | setConnected(false); 114 | } 115 | }; 116 | 117 | const handleNetworkChanged = (network: string) => { 118 | console.log("network changed", network); 119 | setNetwork(network); 120 | getBasicInfo(); 121 | }; 122 | 123 | const handleChainChanged = (chain: { 124 | enum: ChainType; 125 | name: string; 126 | network: string; 127 | }) => { 128 | console.log("chain changed", chain); 129 | setChainType(chain.enum); 130 | getBasicInfo(); 131 | }; 132 | 133 | useEffect(() => { 134 | async function checkUnisat() { 135 | let unisat = (window as any).unisat; 136 | 137 | for (let i = 1; i < 10 && !unisat; i += 1) { 138 | await new Promise((resolve) => setTimeout(resolve, 100 * i)); 139 | unisat = (window as any).unisat; 140 | } 141 | 142 | if (unisat) { 143 | setUnisatInstalled(true); 144 | } else if (!unisat) return; 145 | 146 | unisat 147 | .getAccounts() 148 | .then((accounts: string[]) => { 149 | // obtain account information once 150 | handleAccountsChanged(accounts); 151 | }) 152 | .catch((e: any) => { 153 | messageApi.error((e as any).message); 154 | }); 155 | 156 | unisat.on("accountsChanged", handleAccountsChanged); 157 | unisat.on("networkChanged", handleNetworkChanged); 158 | unisat.on("chainChanged", handleChainChanged); 159 | 160 | return () => { 161 | unisat.removeListener("accountsChanged", handleAccountsChanged); 162 | unisat.removeListener("networkChanged", handleNetworkChanged); 163 | unisat.removeListener("chainChanged", handleChainChanged); 164 | }; 165 | } 166 | 167 | checkUnisat().then(); 168 | }, []); 169 | 170 | const [messageApi, contextHolder] = useMessage(); 171 | 172 | if (!unisatInstalled) { 173 | return ( 174 |
175 |
176 | {contextHolder} 177 |
178 | 185 |
186 |
187 |
188 | ); 189 | } 190 | 191 | const unisat = (window as any).unisat; 192 | 193 | const items: CollapseProps["items"] = [ 194 | { 195 | key: "sendBitcoin", 196 | label:
unisat.sendBitcoin
, 197 | children: , 198 | }, 199 | { 200 | key: "sendInscription", 201 | label:
unisat.sendInscription
, 202 | children: , 203 | }, 204 | 205 | { 206 | key: "sendRunes", 207 | label:
unisat.sendRunes
, 208 | children: , 209 | }, 210 | { 211 | key: "inscribeTransfer", 212 | label:
unisat.inscribeTransfer
, 213 | children: , 214 | }, 215 | { 216 | key: "signMessage", 217 | label:
unisat.signMessage
, 218 | children: , 219 | }, 220 | { 221 | key: "signPsbt", 222 | label:
unisat.signPsbt
, 223 | children: , 224 | }, 225 | { 226 | key: "pushPsbt", 227 | label:
unisat.signPsbt
, 228 | children: , 229 | }, 230 | { 231 | key: "pushTx", 232 | label:
unisat.pushTx
, 233 | children: , 234 | }, 235 | ]; 236 | 237 | const chains = Object.keys(CHAINS_MAP).map((key) => { 238 | const chain = CHAINS_MAP[key as ChainType]; 239 | return { 240 | label: chain.label, 241 | value: chain.enum, 242 | }; 243 | }); 244 | 245 | const supportLegacyNetworks = ["livenet", "testnet"]; 246 | return ( 247 |
248 |
249 |
260 |
261 | {/*

Unisat Wallet Demo

*/} 262 |
263 | {connected ? ( 264 | 272 | ) : null} 273 |
274 |
275 | 276 | {contextHolder} 277 | {connected ? ( 278 |
284 |
294 | 300 | {/*
301 |
Version:
302 |
{version}
303 |
*/} 304 | 305 | {chain ? ( 306 |
307 |
Chain:
308 | { 310 | try { 311 | const chain = await unisat.switchChain( 312 | e.target.value 313 | ); 314 | setChainType(chain.enum); 315 | } catch (e) { 316 | messageApi.error((e as any).message); 317 | } 318 | }} 319 | value={chain.enum} 320 | style={{ display: "flex", flexDirection: "column", gap: "8px" }} 321 | > 322 | {chains.map((chain) => ( 323 | {chain.label} 324 | ))} 325 | 326 |
327 | ) : null} 328 | 329 |
330 |
Network:
331 | {supportLegacyNetworks.includes(network) ? ( 332 | { 334 | try { 335 | const network = await unisat.switchNetwork( 336 | e.target.value 337 | ); 338 | setNetwork(network); 339 | } catch (e) { 340 | messageApi.error((e as any).message); 341 | } 342 | }} 343 | value={network} 344 | > 345 | livenet 346 | testnet 347 | 348 | ) : ( 349 |
350 |

351 | "unisat.getNetwork" is legacy. Please use 352 | "unisat.getChain" instead.{" "} 353 |

354 |
355 | )} 356 |
357 |
358 |
Address:
359 |
{ 362 | copyToClipboard(address); 363 | messageApi.success("Address Copied."); 364 | }} 365 | > 366 | {address} 367 |
368 |
PublicKey:
369 |
{ 372 | copyToClipboard(publicKey); 373 | messageApi.success("PublicKey Copied."); 374 | }} 375 | > 376 | {publicKey} 377 |
378 |
Balance:
379 |
380 | {satoshisToAmount(balance.total)} {chain && chain.unit} 381 |
382 |
383 |
384 | {/* 389 |
390 |
Address:
391 |
{ 394 | copyToClipboard(address); 395 | messageApi.success("Address Copied."); 396 | }} 397 | > 398 | {address} 399 |
400 |
401 | 402 |
403 |
PublicKey:
404 |
{ 407 | copyToClipboard(publicKey); 408 | messageApi.success("PublicKey Copied."); 409 | }} 410 | > 411 | {publicKey} 412 |
413 |
414 | 415 |
416 |
Balance:
417 |
418 | {satoshisToAmount(balance.total)} {chain && chain.unit} 419 |
420 |
421 |
*/} 422 | { 431 | // todo 432 | }} 433 | /> 434 |
435 | 436 |
437 | ) : ( 438 |
439 | 451 |
452 | )} 453 |
454 |
455 | ); 456 | } 457 | 458 | export default App; 459 | --------------------------------------------------------------------------------