diff --git a/example/package-lock.json b/example/package-lock.json index 99673d6..f644a6e 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -23,7 +23,7 @@ "version": "2.2.0", "license": "ISC", "dependencies": { - "@sats-connect/core": "0.0.5", + "@sats-connect/core": "0.0.6", "@sats-connect/make-default-provider-config": "0.0.1", "@sats-connect/ui": "0.0.4" }, diff --git a/example/src/App.tsx b/example/src/App.tsx index 2a9807c..0daa8b5 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -1,6 +1,13 @@ import Wallet, { Address, BitcoinNetworkType, AddressPurpose } from 'sats-connect'; import './App.css'; -import { AddressDisplay, NetworkSelector, SendBtc, SendStx, MintRunes } from './components'; +import { + AddressDisplay, + NetworkSelector, + SendBtc, + SendStx, + MintRunes, + EtchRunes, +} from './components'; import { useLocalStorage } from './hooks'; function App() { @@ -51,6 +58,7 @@ function App() { + ); diff --git a/example/src/components/EtchRunes/index.tsx b/example/src/components/EtchRunes/index.tsx new file mode 100644 index 0000000..cd25d18 --- /dev/null +++ b/example/src/components/EtchRunes/index.tsx @@ -0,0 +1,171 @@ +import { useMemo, useState } from 'react'; +import Wallet, { Address, AddressPurpose, BitcoinNetworkType } from 'sats-connect'; + +type Props = { + network: BitcoinNetworkType; + addresses: Address[]; +}; + +const EtchRunes = ({ addresses, network }: Props) => { + const [totalCost, setTotalCost] = useState(); + const [totalSize, setTotalSize] = useState(); + const [fundTxId, setFundTxId] = useState(''); + const [runeName, setRuneName] = useState(''); + const [feeRate, setFeeRate] = useState(''); + const [symbol, setSymbol] = useState(''); + const [preMine, setPreMine] = useState(''); + const [divisibility, setDivisibility] = useState(''); + const [amount, setAmount] = useState(''); + const [mintCap, setMintCap] = useState(''); + + const ordinalsAddress = useMemo( + () => addresses.find((a) => a.purpose === AddressPurpose.Ordinals)?.address || '', + [addresses] + ); + + const paymentAddress = useMemo( + () => addresses.find((a) => a.purpose === AddressPurpose.Payment)?.address || '', + [addresses] + ); + + const onClickEstimate = async () => { + const response = await Wallet.request('runes_estimateEtch', { + destinationAddress: ordinalsAddress, + feeRate: +feeRate, + symbol: symbol || undefined, + premine: preMine || undefined, + divisibility: +divisibility || undefined, + terms: + amount || mintCap + ? { + amount: amount || undefined, + cap: mintCap || undefined, + } + : undefined, + isMintable: true, + runeName: runeName, + network: network, + }); + + if (response.status === 'success') { + setTotalCost(response.result.totalCost); + setTotalSize(response.result.totalSize); + } else { + console.error(response.error); + alert('Error Fetching Estimate. See console for details.'); + } + }; + + const onClickExecute = async () => { + const response = await Wallet.request('runes_etch', { + destinationAddress: ordinalsAddress, + symbol: symbol || undefined, + premine: preMine || undefined, + terms: + amount || mintCap + ? { + amount: amount || undefined, + cap: mintCap || undefined, + } + : undefined, + feeRate: +feeRate, + isMintable: true, + runeName, + refundAddress: paymentAddress, + network, + }); + + if (response.status === 'success') { + setFundTxId(response.result.fundTransactionId); + } else { + console.error(response.error); + alert('Error sending BTC. See console for details.'); + } + }; + + const fundTxLink = + network === BitcoinNetworkType.Mainnet + ? `https://mempool.space/tx/${fundTxId}` + : `https://mempool.space/testnet/tx/${fundTxId}`; + + return ( + <> +
+

Etch Runes

+
+
+

Rune Name

+ setRuneName(e.target.value)} /> +
+
+

Symbol

+ setSymbol(e.target.value)} /> +
+
+

Divisibility

+ setDivisibility(e.target.value)} + /> +
+
+

Premine

+ setPreMine(e.target.value)} /> +
+
+

Amount

+ setAmount(e.target.value)} /> +
+
+

Mint Cap

+ setMintCap(e.target.value)} /> +
+
+

feeRate (sats/vb)

+ setFeeRate(e.target.value)} /> +
+
+ + +
+ + {totalCost && ( +
+
+

Rune Name

+

{runeName}

+
+
+

Total Cost (sats) - Total Size

+

+ {totalCost} - {totalSize} +

+
+ + {fundTxId && ( +
+ Success! Click{' '} + + here + {' '} + to see your transaction +
+ )} +
+ )} + + ); +}; + +export default EtchRunes; diff --git a/example/src/components/index.ts b/example/src/components/index.ts index f6ea304..1debe0a 100644 --- a/example/src/components/index.ts +++ b/example/src/components/index.ts @@ -3,3 +3,4 @@ export { default as NetworkSelector } from './NetworkSelector'; export { default as SendBtc } from './SendBtc'; export { default as SendStx } from './SendStx'; export { default as MintRunes } from './MintRunes'; +export { default as EtchRunes } from './EtchRunes'; diff --git a/package-lock.json b/package-lock.json index 6410633..c405288 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.2.0", "license": "ISC", "dependencies": { - "@sats-connect/core": "0.0.5", + "@sats-connect/core": "0.0.6", "@sats-connect/make-default-provider-config": "0.0.1", "@sats-connect/ui": "0.0.4" }, @@ -1748,9 +1748,9 @@ ] }, "node_modules/@sats-connect/core": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.0.5.tgz", - "integrity": "sha512-eyAoxjs3vuJP037/XKuhjIDUrOlCHIdcvw2D1DFpzhTRzyiXptiE2A0n46loDIBCUhOuXl4vsn8cc+yC2jzGCg==", + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.0.6.tgz", + "integrity": "sha512-ShKqJamN1DQkeLAuzA2Clpu9R5jN6hhrm2UHoxnuNWWhkLK4koRbyOnJzxjkOpImtSd7MDEMibqt9NiKR/r8ow==", "dependencies": { "axios": "1.6.8", "bitcoin-address-validation": "2.2.3", @@ -7337,9 +7337,9 @@ "optional": true }, "@sats-connect/core": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.0.5.tgz", - "integrity": "sha512-eyAoxjs3vuJP037/XKuhjIDUrOlCHIdcvw2D1DFpzhTRzyiXptiE2A0n46loDIBCUhOuXl4vsn8cc+yC2jzGCg==", + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.0.6.tgz", + "integrity": "sha512-ShKqJamN1DQkeLAuzA2Clpu9R5jN6hhrm2UHoxnuNWWhkLK4koRbyOnJzxjkOpImtSd7MDEMibqt9NiKR/r8ow==", "requires": { "axios": "1.6.8", "bitcoin-address-validation": "2.2.3", diff --git a/package.json b/package.json index d1ce671..87c3595 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "scripts": { "test": "jest", "build": "npm run clean && tsup src/index.ts --format esm --dts", + "dev:build": "tsup src/index.ts --format esm --dts --watch", "dev:example": "cd example && npm start", "clean": "rimraf dist", "lint": "prettier --write .", @@ -22,7 +23,7 @@ ] }, "dependencies": { - "@sats-connect/core": "0.0.5", + "@sats-connect/core": "0.0.6", "@sats-connect/ui": "0.0.4", "@sats-connect/make-default-provider-config": "0.0.1" }, diff --git a/src/index.ts b/src/index.ts index c959cb3..565ee25 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,23 +25,21 @@ import { makeDefaultConfig } from '@sats-connect/make-default-provider-config'; loadSelector(); class Wallet { - private static providerId: string | undefined; + private providerId: string | undefined; - private static defaultAdapters: Record SatsConnectAdapter> = defaultAdapters; + private defaultAdapters: Record SatsConnectAdapter> = defaultAdapters; - private static createCustomConfig?: (providers: SupportedWallet[]) => Config; + private createCustomConfig?: (providers: SupportedWallet[]) => Config; - private static isProviderSet(): boolean { + private isProviderSet(): boolean { return !!this.providerId; } - public static setCreateCustomConfig( - createCustomConfig: (providers: SupportedWallet[]) => Config - ) { + public setCreateCustomConfig(createCustomConfig: (providers: SupportedWallet[]) => Config) { this.createCustomConfig = createCustomConfig; } - public static async selectProvider() { + public async selectProvider() { const providers = getSupportedWallets(); if (providers.length === 0) { @@ -57,12 +55,12 @@ class Wallet { this.providerId = nextProviderId; } - public static async disconnect() { + public async disconnect() { this.providerId = undefined; removeDefaultProvider(); } - public static async request( + public async request( method: Method, params: Params ): Promise> { @@ -114,4 +112,4 @@ class Wallet { export * from '@sats-connect/core'; -export default Wallet; +export default new Wallet();