-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
etching example + cleanup #99
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a5fb08b
added etching example
m-aboelenein f9d624a
added an amount and cap fields to etch
m-aboelenein f8f4e84
update core version
m-aboelenein 095b303
update core + export wallet instance
m-aboelenein 1a0c837
update core version
m-aboelenein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,147 @@ | ||
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<number>(); | ||
const [totalSize, setTotalSize] = useState<number>(); | ||
const [fundTxId, setFundTxId] = useState<string>(''); | ||
const [runeName, setRuneName] = useState<string>(''); | ||
const [feeRate, setFeeRate] = useState<string>(''); | ||
const [symbol, setSymbol] = useState<string>(''); | ||
const [preMine, setPreMine] = useState<string>(''); | ||
const [divisibility, setDivisibility] = useState<string>(''); | ||
|
||
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, | ||
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, | ||
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 ( | ||
<> | ||
<div className="card"> | ||
<h3>Etch Runes</h3> | ||
<div | ||
style={{ | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
justifyContent: 'space-between', | ||
paddingRight: 100, | ||
marginBottom: 20, | ||
}} | ||
> | ||
<div> | ||
<h4>Rune Name</h4> | ||
<input type="text" value={runeName} onChange={(e) => setRuneName(e.target.value)} /> | ||
</div> | ||
<div> | ||
<h4>Symbol</h4> | ||
<input type="text" value={symbol} onChange={(e) => setSymbol(e.target.value)} /> | ||
</div> | ||
<div> | ||
<h4>Divisibility</h4> | ||
<input | ||
type="number" | ||
value={divisibility} | ||
onChange={(e) => setDivisibility(e.target.value)} | ||
/> | ||
</div> | ||
<div> | ||
<h4>Premine</h4> | ||
<input type="number" value={preMine} onChange={(e) => setPreMine(e.target.value)} /> | ||
</div> | ||
<div> | ||
<h4>feeRate (sats/vb)</h4> | ||
<input type="number" value={feeRate} onChange={(e) => setFeeRate(e.target.value)} /> | ||
</div> | ||
</div> | ||
|
||
<button onClick={onClickEstimate} disabled={!runeName || !feeRate}> | ||
Estimate Etch | ||
</button> | ||
</div> | ||
|
||
{totalCost && ( | ||
<div className="card"> | ||
<div> | ||
<h3>Rune Name</h3> | ||
<p className="success">{runeName}</p> | ||
</div> | ||
<div> | ||
<h3>Total Cost (sats) - Total Size</h3> | ||
<p className="success"> | ||
{totalCost} - {totalSize} | ||
</p> | ||
</div> | ||
<button onClick={onClickExecute}>Execute Etch</button> | ||
{fundTxId && ( | ||
<div className="success"> | ||
Success! Click{' '} | ||
<a href={fundTxLink} target="_blank" rel="noreferrer"> | ||
here | ||
</a>{' '} | ||
to see your transaction | ||
</div> | ||
)} | ||
</div> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default EtchRunes; |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add an amount & cap. Open mints without a cap are unmintable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens on the service if you submit an order with
isMintable=true
and no amount & cap?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will throw a 400
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be caught in the sats-connect method and would return an error result here, so maybe that's enough?