Update index.html
This commit is contained in:
parent
38cfa7428f
commit
52ff5e1219
174
index.html
174
index.html
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
@ -341,6 +340,7 @@
|
|||||||
src="scripts/btcwallet_scripts_lib.js"
|
src="scripts/btcwallet_scripts_lib.js"
|
||||||
type="text/javascript"
|
type="text/javascript"
|
||||||
></script>
|
></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/gh/ethereumjs/browser-builds/dist/ethereumjs-tx/ethereumjs-tx-1.3.3.min.js"></script>
|
||||||
<script src="scripts/btcOperator.js" type="text/javascript"></script>
|
<script src="scripts/btcOperator.js" type="text/javascript"></script>
|
||||||
<script src="scripts/floCrypto.js" type="text/javascript"></script>
|
<script src="scripts/floCrypto.js" type="text/javascript"></script>
|
||||||
<script src="scripts/floSolana.js" type="text/javascript"></script>
|
<script src="scripts/floSolana.js" type="text/javascript"></script>
|
||||||
@ -411,9 +411,9 @@
|
|||||||
document.addEventListener("popupclosed", (e) => {
|
document.addEventListener("popupclosed", (e) => {
|
||||||
zIndex--;
|
zIndex--;
|
||||||
switch (e.target.id) {
|
switch (e.target.id) {
|
||||||
case 'retrieve_btc_addr_popup':
|
case "retrieve_btc_addr_popup":
|
||||||
getRef('recovered_btc_addr_wrapper').classList.add('hidden')
|
getRef("recovered_btc_addr_wrapper").classList.add("hidden");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//Function for displaying toast notifications. pass in error for mode param if you want to show an error.
|
//Function for displaying toast notifications. pass in error for mode param if you want to show an error.
|
||||||
@ -705,8 +705,7 @@
|
|||||||
if (!value)
|
if (!value)
|
||||||
return {
|
return {
|
||||||
isValid: false,
|
isValid: false,
|
||||||
errorText:
|
errorText: "Please enter a Solana Seed",
|
||||||
"Please enter a Solana Seed",
|
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
isValid: (() => {
|
isValid: (() => {
|
||||||
@ -1067,10 +1066,22 @@
|
|||||||
class="contact"
|
class="contact"
|
||||||
.dataset=${{ address: walletAddress }}
|
.dataset=${{ address: walletAddress }}
|
||||||
>
|
>
|
||||||
<sm-copy value="${walletAddress}"></sm-copy>
|
|
||||||
${!isFloAddr
|
${!isFloAddr
|
||||||
? null
|
? html`<sm-copy value="${walletAddress}"></sm-copy>`
|
||||||
: html`<sm-copy value="${isFloAddr}"></sm-copy>`}
|
: html`<sm-chips
|
||||||
|
onchange=${(e) =>
|
||||||
|
(e.target
|
||||||
|
.closest(".contact")
|
||||||
|
.querySelector("sm-copy").value = e.target.value)}
|
||||||
|
>
|
||||||
|
<sm-chip value=${walletAddress} selected>SOL</sm-chip>
|
||||||
|
<sm-chip value=${isFloAddr}
|
||||||
|
>${isFloAddr.startsWith("bc")
|
||||||
|
? "BTC"
|
||||||
|
: "FLO"}</sm-chip
|
||||||
|
>
|
||||||
|
</sm-chips>
|
||||||
|
<sm-copy value="${walletAddress}"></sm-copy>`}
|
||||||
<div class="flex align-center space-between gap-0-5">
|
<div class="flex align-center space-between gap-0-5">
|
||||||
<button
|
<button
|
||||||
class="button button--small"
|
class="button button--small"
|
||||||
@ -1474,9 +1485,9 @@
|
|||||||
const receiver = getRef("send_tx_form")
|
const receiver = getRef("send_tx_form")
|
||||||
.querySelector(".receiver-address")
|
.querySelector(".receiver-address")
|
||||||
.value.trim();
|
.value.trim();
|
||||||
const amount = getRef("send_tx_form")
|
const amount = parseFloat(
|
||||||
.querySelector(".receiver-amount")
|
getRef("send_tx_form").querySelector(".receiver-amount").value.trim()
|
||||||
.value.trim();
|
);
|
||||||
const asset = "sol";
|
const asset = "sol";
|
||||||
try {
|
try {
|
||||||
const confirmation = await getConfirmation("Send transaction", {
|
const confirmation = await getConfirmation("Send transaction", {
|
||||||
@ -1485,77 +1496,92 @@
|
|||||||
});
|
});
|
||||||
buttonLoader("send_tx_button", true);
|
buttonLoader("send_tx_button", true);
|
||||||
if (!confirmation) return;
|
if (!confirmation) return;
|
||||||
|
|
||||||
const secret = getRef("private_key_input").value.trim();
|
const secret = getRef("private_key_input").value.trim();
|
||||||
const pKey =
|
const pKey =
|
||||||
secret.length < 64
|
secret.length < 64
|
||||||
? floSolana.wif2SolanaSecret(secret)
|
? floSolana.wif2SolanaSecret(secret)
|
||||||
: floSolana.solanaSeed2SolanaSecret(secret);
|
: floSolana.solanaSeed2SolanaSecret(secret);
|
||||||
let privateKey = floSolana.solanaSecret2UsableInCode(pKey);
|
let privateKey = floSolana.solanaSecret2UsableInCode(pKey);
|
||||||
|
|
||||||
console.log("private key", privateKey);
|
console.log("private key", privateKey);
|
||||||
const senderPrivateKeyArray = privateKey;
|
const senderKeypair = solanaWeb3.Keypair.fromSecretKey(privateKey);
|
||||||
const senderKeypair = solanaWeb3.Keypair.fromSecretKey(
|
|
||||||
senderPrivateKeyArray
|
// if (/^[0-9a-fA-F]{64}$/.test(privateKey)) {
|
||||||
|
// privateKey = coinjs.privkey2wif(privateKey);
|
||||||
|
// }
|
||||||
|
// privateKey = coinjs.wif2privkey(privateKey).privkey;
|
||||||
|
|
||||||
|
const receiverPublicKey = new solanaWeb3.PublicKey(receiver);
|
||||||
|
console.log("receiver", receiverPublicKey);
|
||||||
|
Buffer = ethereumjs.Buffer.Buffer;
|
||||||
|
const transaction = new solanaWeb3.Transaction().add(
|
||||||
|
solanaWeb3.SystemProgram.transfer({
|
||||||
|
fromPubkey: senderKeypair.publicKey,
|
||||||
|
toPubkey: receiverPublicKey,
|
||||||
|
lamports: amount * solanaWeb3.LAMPORTS_PER_SOL, // Convert SOL to lamports
|
||||||
|
})
|
||||||
);
|
);
|
||||||
if (/^[0-9a-fA-F]{64}$/.test(privateKey)) {
|
const connection = new solanaWeb3.Connection(
|
||||||
privateKey = coinjs.privkey2wif(privateKey);
|
"https://solana-mainnet.core.chainstack.com/3eb691b8be8f475e3a74f765abfa0b03",
|
||||||
}
|
{
|
||||||
privateKey = coinjs.wif2privkey(privateKey).privkey;
|
wsEndpoint:
|
||||||
switch (asset) {
|
"wss://solana-mainnet.core.chainstack.com/3eb691b8be8f475e3a74f765abfa0b03",
|
||||||
case "sol": {
|
|
||||||
const receiverPublicKey = new solanaWeb3.PublicKey(receiver);
|
|
||||||
console.log("reciver", receiverPublicKey);
|
|
||||||
const transaction = new solanaWeb3.Transaction().add(
|
|
||||||
solanaWeb3.SystemProgram.transfer({
|
|
||||||
fromPubkey: senderKeypair.publicKey,
|
|
||||||
toPubkey: receiverPublicKey,
|
|
||||||
lamports: amount * solanaWeb3.LAMPORTS_PER_SOL, // Convert SOL to lamports
|
|
||||||
})
|
|
||||||
);
|
|
||||||
const signature = await solanaWeb3.sendAndConfirmTransaction(
|
|
||||||
getWalletBalance.connection,
|
|
||||||
transaction,
|
|
||||||
[senderKeypair]
|
|
||||||
);
|
|
||||||
showTransactionResult("pending", { txHash: signature });
|
|
||||||
await signature.wait();
|
|
||||||
showTransactionResult("confirmed", { txHash: signature });
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case "usdc":
|
);
|
||||||
case "usdt": {
|
const signature = await solanaWeb3.sendAndConfirmTransaction(
|
||||||
const tx = await ethOperator.sendToken({
|
connection,
|
||||||
privateKey,
|
transaction,
|
||||||
receiver,
|
[senderKeypair]
|
||||||
amount,
|
);
|
||||||
token: asset,
|
showTransactionResult("pending", { txHash: signature });
|
||||||
});
|
await signature.wait();
|
||||||
showTransactionResult("pending", { txHash: tx.hash });
|
showTransactionResult("confirmed", { txHash: signature });
|
||||||
await tx.wait();
|
|
||||||
showTransactionResult("confirmed", { txHash: tx.hash });
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
getRef("send_tx_form").reset();
|
getRef("send_tx_form").reset();
|
||||||
getRef("sender_balance_container").classList.add("hidden");
|
getRef("sender_balance_container").classList.add("hidden");
|
||||||
|
|
||||||
|
const addressOfKey = floSolana.solanaSeed2SolanaAddress(secret);
|
||||||
|
const balance = await walletBalance(addressOfKey);
|
||||||
|
console.log("balance", balance);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e.message);
|
console.error(e.message);
|
||||||
notify(e.message, "error");
|
if (e instanceof solanaWeb3.SendTransactionError) {
|
||||||
const regex = /\(error=({.*?}),/;
|
console.error("Transaction simulation failed:", e.message);
|
||||||
const match = e.message.match(regex);
|
|
||||||
if (match && match[1]) {
|
// Attempt to get logs
|
||||||
const { code } = JSON.parse(match[1]);
|
const logs = e.getLogs();
|
||||||
if (code === -32000)
|
if (logs && logs.length > 0) {
|
||||||
showTransactionResult("failed", {
|
console.error("Transaction logs:", logs);
|
||||||
description: `Insufficient ${asset.toUpperCase()} balance`,
|
} else {
|
||||||
});
|
console.error("No logs available.");
|
||||||
else {
|
}
|
||||||
|
notify("Transaction failed. Please check your account balance and try again.", "error")
|
||||||
|
showTransactionResult("failed", { description: "Transaction failed. Please check your account balance and try again." });
|
||||||
|
}
|
||||||
|
if (e.message) {
|
||||||
|
const regex = /\(error=({.*?}),/;
|
||||||
|
const match = e.message.match(regex);
|
||||||
|
if (match && match[1]) {
|
||||||
|
const { code } = JSON.parse(match[1]);
|
||||||
|
if (code === -32000) {
|
||||||
|
showTransactionResult("failed", {
|
||||||
|
description: `Insufficient ${asset.toUpperCase()} balance`,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
showTransactionResult("failed", { description: e.message });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
showTransactionResult("failed", { description: e.message });
|
showTransactionResult("failed", { description: e.message });
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
showTransactionResult("failed", { description: e.message });
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
buttonLoader("send_tx_button", false);
|
buttonLoader("send_tx_button", false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function showTransactionResult(status, { txHash, description = "" }) {
|
function showTransactionResult(status, { txHash, description = "" }) {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case "pending":
|
case "pending":
|
||||||
@ -1759,18 +1785,18 @@
|
|||||||
return uint8Array;
|
return uint8Array;
|
||||||
}
|
}
|
||||||
function retrieveSolanaAddr() {
|
function retrieveSolanaAddr() {
|
||||||
function retrieve() {
|
function retrieve() {
|
||||||
let seed = getRef('retrieve_btc_addr_field').value.trim();
|
let seed = getRef("retrieve_btc_addr_field").value.trim();
|
||||||
getRef('recovered_btc_addr_wrapper').classList.remove('hidden')
|
getRef("recovered_btc_addr_wrapper").classList.remove("hidden");
|
||||||
getRef('recovered_btc_addr').value = floSolana.solanaSeed2SolanaAddress(seed);
|
getRef("recovered_btc_addr").value =
|
||||||
}
|
floSolana.solanaSeed2SolanaAddress(seed);
|
||||||
if (document.startViewTransition) {
|
|
||||||
document.startViewTransition(() => {
|
|
||||||
retrieve()
|
|
||||||
})
|
|
||||||
} else
|
|
||||||
retrieve()
|
|
||||||
}
|
}
|
||||||
|
if (document.startViewTransition) {
|
||||||
|
document.startViewTransition(() => {
|
||||||
|
retrieve();
|
||||||
|
});
|
||||||
|
} else retrieve();
|
||||||
|
}
|
||||||
|
|
||||||
function generateNewID() {
|
function generateNewID() {
|
||||||
const solanaKeyPair = floSolana.generateSolanaKeyPair();
|
const solanaKeyPair = floSolana.generateSolanaKeyPair();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user