diff --git a/src/components/Contracts.tsx b/src/components/Contracts.tsx index 191b2d5..56aeb92 100644 --- a/src/components/Contracts.tsx +++ b/src/components/Contracts.tsx @@ -2,8 +2,9 @@ import React from 'react' import CopyText from './shared/CopyText' import { Card, Button } from 'react-bootstrap' import { ContractInfo } from './shared' -import InfoUtxos from './InfoUtxos' +import InfoUtxos from './shared/InfoUtxos' import { MockNetworkProvider, NetworkProvider, randomUtxo } from 'cashscript' +import CreateUtxo from './shared/CreateUtxo' interface Props { provider: NetworkProvider @@ -93,9 +94,10 @@ const Contracts: React.FC = ({ provider, contracts, setContracts, updateU
addRandomUtxo(contractInfo)} style={{cursor:"pointer"}}>
-
+
Create custom utxo -

coming soon...

+ updateUtxosContract(contractInfo.contract.name)}/>
) : null} Total contract balance diff --git a/src/components/Wallets.tsx b/src/components/Wallets.tsx index dcd2db7..2d6e5d7 100644 --- a/src/components/Wallets.tsx +++ b/src/components/Wallets.tsx @@ -13,7 +13,8 @@ import { encodePrivateKeyWif, } from '@bitauth/libauth' import CopyText from './shared/CopyText' -import InfoUtxos from './InfoUtxos' +import InfoUtxos from './shared/InfoUtxos' +import CreateUtxo from './shared/CreateUtxo' interface Props { provider: NetworkProvider @@ -172,10 +173,10 @@ const WalletInfo: React.FC = ({provider, wallets, setWallets}) => {
addRandomUtxo(wallet, index)} style={{cursor:"pointer"}}>
-
+
Create custom utxo -

coming soon...

-
+ updateUtxosWallet(wallet,index)}/> +
) : null} Wallet Balance
{wallet.utxos?.reduce((acc, utxo) => acc + utxo.satoshis, 0n).toString()} satoshis
diff --git a/src/components/shared/CreateUtxo.tsx b/src/components/shared/CreateUtxo.tsx new file mode 100644 index 0000000..0435221 --- /dev/null +++ b/src/components/shared/CreateUtxo.tsx @@ -0,0 +1,81 @@ +import React, { useState } from 'react' +import { MockNetworkProvider, NetworkProvider, Utxo } from 'cashscript' +import { Form, InputGroup, Button, Card } from 'react-bootstrap' + +interface Props { + provider: NetworkProvider + address: string + updateUtxos: (() => Promise) | (() => void) +} + +const CreateUtxo: React.FC = ({provider, address, updateUtxos}) => { + const [customUtxo, setCustomUtxo] = useState({txid: "", satoshis: 0n, vout: 0}) + // const [hasFT, setHasFT] = useState(false) + // const [hasNFT, setHasNFT] = useState(false) + + const addCustomUtxo = () => { + try{ + if(!(provider instanceof MockNetworkProvider)) return + if(customUtxo.satoshis < 546n) throw new Error('Utxo must have atleast 546n sats') + provider.addUtxo(address, customUtxo) + updateUtxos() + } catch(e){ + alert(e) + } + } + + return ( +
+ Fill in (partial) utxo data: +
+
+ + { + const utxoCopy = { ...customUtxo } + utxoCopy.txid = event.target.value as string + setCustomUtxo(utxoCopy) + }} + /> + { + const utxoCopy = { ...customUtxo } + utxoCopy.vout = parseInt(event.target.value) + setCustomUtxo(utxoCopy) + }} + /> + +
+
+ + { + const utxoCopy = { ...customUtxo } + utxoCopy.satoshis = BigInt(event.target.value) + setCustomUtxo(utxoCopy) + }} + /> + +
+ {/* +
+ console.log("b")} + /> + */} +
+ +
+ ) +} + +export default CreateUtxo \ No newline at end of file diff --git a/src/components/InfoUtxos.tsx b/src/components/shared/InfoUtxos.tsx similarity index 100% rename from src/components/InfoUtxos.tsx rename to src/components/shared/InfoUtxos.tsx