Skip to content

Commit

Permalink
Transfer commitment caching ++ correct decimal handling
Browse files Browse the repository at this point in the history
  • Loading branch information
KaffinPX committed Sep 17, 2024
1 parent 67362cc commit 4fc5f59
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/pages/Account/Tokens/Transact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function Transfer ({ ticker }: {
ticker: string
}) {
const { address, balances } = useAccount()
const { networkId } = useIndexer()
const { networkId, tokens } = useIndexer()
const { invoke } = useKaspian()

const [ recipient, setRecipient ] = useState<string>('')
Expand All @@ -32,16 +32,19 @@ function Transfer ({ ticker }: {
const script = new ScriptBuilder()
const inscription = new Inscription('transfer', {
tick: ticker,
amt: BigInt(Number(amount) * 1e8).toString(),
amt: BigInt(Number(amount) * (1 ** parseInt(tokens[ticker].dec))).toString(),
to: recipient.toString()
})

inscription.write(script, XOnlyPublicKey.fromAddress(new Address(address!)).toString())

const scriptAddress = addressFromScriptPublicKey(script.createPayToScriptHashScript(), networkId!)!.toString()
const commitment = localStorage.getItem(scriptAddress)

setScript(script.toString())
setCommitAddress(addressFromScriptPublicKey(script.createPayToScriptHashScript(), networkId!)!.toString())
if (commitment) setCommit(commitment)
setCommitAddress(scriptAddress)
}, [ address, recipient, amount ])

return (
<Dialog>
<DialogTrigger asChild>
Expand Down

0 comments on commit 4fc5f59

Please sign in to comment.