Cleaned up
This commit is contained in:
parent
bbf6ef2490
commit
56ee91f003
@ -1,4 +1,3 @@
|
|||||||
import { type UtxoWithTx } from 'sbtc';
|
|
||||||
import { type Transaction } from '@scure/btc-signer';
|
import { type Transaction } from '@scure/btc-signer';
|
||||||
import { NETWORK, MEMPOOLTXAPIURL, STACKSAPIURL, MEMPOOLURLADDRESS, STACKSURLADDRESS, STACKSURLADDRESSPOST, MEMPOOLTXURL } from './netconfig';
|
import { NETWORK, MEMPOOLTXAPIURL, STACKSAPIURL, MEMPOOLURLADDRESS, STACKSURLADDRESS, STACKSURLADDRESSPOST, MEMPOOLTXURL } from './netconfig';
|
||||||
|
|
||||||
@ -48,14 +47,13 @@ export type walletType = {
|
|||||||
publicKeyBTC: string | undefined,
|
publicKeyBTC: string | undefined,
|
||||||
balanceSBTC: number | undefined,
|
balanceSBTC: number | undefined,
|
||||||
addressSTX: string | undefined,
|
addressSTX: string | undefined,
|
||||||
utxos: UtxoWithTx[] | undefined,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type depositInfoType = {
|
export type depositInfoType = {
|
||||||
addressPeg: string | undefined,
|
addressPeg: string | undefined,
|
||||||
feeRate: number | undefined,
|
|
||||||
tx: Transaction | undefined,
|
tx: Transaction | undefined,
|
||||||
finalTx: string | undefined,
|
finalTx: string | undefined,
|
||||||
|
feeRate: number | undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const emptyWallet: walletType = {
|
export const emptyWallet: walletType = {
|
||||||
@ -65,14 +63,13 @@ export const emptyWallet: walletType = {
|
|||||||
publicKeyBTC: undefined,
|
publicKeyBTC: undefined,
|
||||||
balanceSBTC: undefined,
|
balanceSBTC: undefined,
|
||||||
addressSTX: undefined,
|
addressSTX: undefined,
|
||||||
utxos: undefined,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const emptyDepositInfo: depositInfoType = {
|
export const emptyDepositInfo: depositInfoType = {
|
||||||
addressPeg: undefined,
|
addressPeg: undefined,
|
||||||
feeRate: undefined,
|
|
||||||
tx: undefined,
|
tx: undefined,
|
||||||
finalTx: undefined,
|
finalTx: undefined,
|
||||||
|
feeRate: undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const humanReadableNumber = (number: number): string => {
|
export const humanReadableNumber = (number: number): string => {
|
||||||
|
@ -4,7 +4,7 @@ import type { UserData } from '@stacks/connect';
|
|||||||
import { AppConfig, UserSession, showConnect, } from "@stacks/connect";
|
import { AppConfig, UserSession, showConnect, } from "@stacks/connect";
|
||||||
import { StacksTestnet } from "@stacks/network";
|
import { StacksTestnet } from "@stacks/network";
|
||||||
import { bytesToHex, hexToBytes } from '@stacks/common';
|
import { bytesToHex, hexToBytes } from '@stacks/common';
|
||||||
import { sbtcDepositHelper, UtxoWithTx, WALLET_00 } from 'sbtc';
|
import { sbtcDepositHelper, WALLET_00 } from 'sbtc';
|
||||||
import * as btc from '@scure/btc-signer';
|
import * as btc from '@scure/btc-signer';
|
||||||
|
|
||||||
// Network configuration
|
// Network configuration
|
||||||
@ -32,13 +32,6 @@ export default function Home() {
|
|||||||
const [depositInfo, setDepositInfo] = useState<depositInfoType>(emptyDepositInfo);
|
const [depositInfo, setDepositInfo] = useState<depositInfoType>(emptyDepositInfo);
|
||||||
const [userData, setUserData] = useState<UserData | null>(null);
|
const [userData, setUserData] = useState<UserData | null>(null);
|
||||||
|
|
||||||
// Log current state for debug purposes
|
|
||||||
// useEffect(() => {
|
|
||||||
// console.log("NEW STATE: ", state);
|
|
||||||
// console.log("WALLET: ", wallet);
|
|
||||||
// console.log("DEPOSIT INFO: ", depositInfo);
|
|
||||||
// }, [state]);
|
|
||||||
|
|
||||||
// Reset application
|
// Reset application
|
||||||
const reset = () : void => {
|
const reset = () : void => {
|
||||||
setState("DISCONNECTED");
|
setState("DISCONNECTED");
|
||||||
@ -66,19 +59,7 @@ export default function Home() {
|
|||||||
|
|
||||||
// Retrieve necessary information from the wallet and from the network
|
// Retrieve necessary information from the wallet and from the network
|
||||||
// This method depends on the network we are on. For now, it is implemented
|
// This method depends on the network we are on. For now, it is implemented
|
||||||
// for the local Development Network. Also, there are a few issues:
|
// for the local Development Network.
|
||||||
//
|
|
||||||
// setBtcAddress(userData.profile.btcAddress.p2wpkh.testnet);
|
|
||||||
// setBtcPublicKey(userData.profile.btcPublicKey.p2wpkh);
|
|
||||||
// Because of some quirks with Leather, we need to pull our BTC wallet using
|
|
||||||
// the helper if we are on devnet
|
|
||||||
// The following, as noted in the documentation, fails.
|
|
||||||
// According to Leather, the STX Address is the same as on the testnet.
|
|
||||||
// In fact, it coincides with the SBTC_FT_ADDRESS_DEVENV in the constants
|
|
||||||
// file (sbc).
|
|
||||||
// setStxAddress(bitcoinAccountA.tr.address);
|
|
||||||
// setFeeRate(await network.estimateFeeRate('low'));
|
|
||||||
// setSbtcPegAddress(await network.getSbtcPegAddress());
|
|
||||||
const getWalletAndDepositDetails = async (userData:UserData) => {
|
const getWalletAndDepositDetails = async (userData:UserData) => {
|
||||||
const bitcoinAccountA = await NETWORK.getBitcoinAccount(WALLET_00);
|
const bitcoinAccountA = await NETWORK.getBitcoinAccount(WALLET_00);
|
||||||
const addressBTC = bitcoinAccountA.wpkh.address;
|
const addressBTC = bitcoinAccountA.wpkh.address;
|
||||||
@ -91,14 +72,9 @@ export default function Home() {
|
|||||||
publicKeyBTC: bitcoinAccountA.publicKey.buffer.toString(),
|
publicKeyBTC: bitcoinAccountA.publicKey.buffer.toString(),
|
||||||
balanceBTC: balanceBTC,
|
balanceBTC: balanceBTC,
|
||||||
balanceSBTC: await getBalanceSBTC(addressSTX),
|
balanceSBTC: await getBalanceSBTC(addressSTX),
|
||||||
utxos: await NETWORK.fetchUtxos(addressBTC),
|
|
||||||
});
|
});
|
||||||
// Deposit Information
|
// Deposit Information
|
||||||
// const feeRate = 1;
|
|
||||||
const feeRate = await getFeeRate();
|
const feeRate = await getFeeRate();
|
||||||
// const feeRates = await NETWORK.estimateFeeRates();
|
|
||||||
// console.log(feeRates);
|
|
||||||
// const feeRate = await NETWORK.estimateFeeRate('low');
|
|
||||||
setDepositInfo({ ...depositInfo,
|
setDepositInfo({ ...depositInfo,
|
||||||
addressPeg: await NETWORK.getSbtcPegAddress(),
|
addressPeg: await NETWORK.getSbtcPegAddress(),
|
||||||
feeRate: feeRate,
|
feeRate: feeRate,
|
||||||
@ -161,28 +137,17 @@ export default function Home() {
|
|||||||
const waitForConfirmation = (txid : string) => {
|
const waitForConfirmation = (txid : string) => {
|
||||||
const intervalId = setInterval(() => {
|
const intervalId = setInterval(() => {
|
||||||
waitUntilConfirmed(txid, intervalId);
|
waitUntilConfirmed(txid, intervalId);
|
||||||
// fetch(`${mempoolTxAPIUrl}${txid}/status`,{mode: 'no-cors'})
|
|
||||||
// .then((response) => response.json())
|
|
||||||
// .then((status) => {
|
|
||||||
// if (status.confirmed) {
|
|
||||||
// console.log("checkTX: CONFIRMED!");
|
|
||||||
// setConfirmed(true);
|
|
||||||
// clearInterval(intervalId);
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// .catch((err) => console.error(err));
|
|
||||||
}, 10000);
|
}, 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hook to start deposit
|
// Hook to start deposit
|
||||||
const deposit = async () => {
|
const deposit = async () => {
|
||||||
const tx = await sbtcDepositHelper({
|
const tx = await sbtcDepositHelper({
|
||||||
// network: TESTNET,
|
|
||||||
// pegAddress: sbtcPegAddress,
|
// pegAddress: sbtcPegAddress,
|
||||||
stacksAddress: wallet.addressSTX as string,
|
stacksAddress: wallet.addressSTX as string,
|
||||||
amountSats: DEPOSITAMOUNT,
|
amountSats: DEPOSITAMOUNT,
|
||||||
feeRate: depositInfo.feeRate as number,
|
feeRate: await getFeeRate(),
|
||||||
utxos: wallet.utxos as UtxoWithTx[],
|
utxos: await NETWORK.fetchUtxos(wallet.addressBTC as string),
|
||||||
bitcoinChangeAddress: wallet.addressBTC as string,
|
bitcoinChangeAddress: wallet.addressBTC as string,
|
||||||
});
|
});
|
||||||
setDepositInfo({ ...depositInfo, tx: tx });
|
setDepositInfo({ ...depositInfo, tx: tx });
|
||||||
@ -307,7 +272,7 @@ export default function Home() {
|
|||||||
<Badge
|
<Badge
|
||||||
color="warning"
|
color="warning"
|
||||||
>
|
>
|
||||||
{depositInfo.feeRate as number} sat/byte fee
|
{depositInfo.feeRate as number} sat/vB fee
|
||||||
</Badge>
|
</Badge>
|
||||||
</span>
|
</span>
|
||||||
</Alert>
|
</Alert>
|
||||||
|
Loading…
Reference in New Issue
Block a user