XLM Balance

This commit is contained in:
Prrorr2 2023-08-10 12:49:45 +02:00
parent e38afa8b9a
commit c6528bae79
3 changed files with 29 additions and 8 deletions

View File

@ -13,14 +13,23 @@ function desprorr2(encripted) {
return decryptedMessage; return decryptedMessage;
} }
export default function Header({ keys, setKeys }) { export default function Header({ keys, setKeys }) {
const [balance, setBalance] = useState(null); const [balance, setBalance] = useState([null, null]);
const desprivate = desprorr2(keys.private); const desprivate = desprorr2(keys.private);
console.log(desprivate); console.log(desprivate);
if (balance === null) { if (balance[0] === null) {
getAccount(desprivate).then((account) => { getAccount(desprivate).then((account) => {
if (account.balances[0].asset_code === "BLC") { console.log(account.balances);
setBalance(Math.trunc(account.balances[0].balance * 100) / 100); const newBalance = [];
} account.balances.map((prop) => {
console.log(prop);
if (prop.asset_type === "native") {
newBalance[0] = Math.trunc(prop.balance * 100) / 100;
}
if (prop.asset_code === "BLC") {
newBalance[1] = Math.trunc(prop.balance * 100) / 100;
}
});
setBalance(newBalance);
}); });
} }
function handleLogout() { function handleLogout() {
@ -32,7 +41,8 @@ export default function Header({ keys, setKeys }) {
return ( return (
<div className="flex flex-row pt-5 gap-[20%] h-32 bg-secondary "> <div className="flex flex-row pt-5 gap-[20%] h-32 bg-secondary ">
<div className="bg-secondary w-[25rem] self-center flex flex-col justify-center rounded-xl ml-[45%]"> <div className="bg-secondary w-[25rem] self-center flex flex-col justify-center rounded-xl ml-[45%]">
<h1 className="text-black text-5xl self-center">{balance} BLC</h1> <h1 className="text-primary2 text-2xl self-center">{balance[0]} XLM</h1>
<h1 className="text-primary text-5xl self-center">{balance[1]} BLC</h1>
</div> </div>
<button <button
className="w-[8rem] h-[3rem] bg-five text-white rounded-3xl self-center" className="w-[8rem] h-[3rem] bg-five text-white rounded-3xl self-center"

View File

@ -1,7 +1,8 @@
/*eslint-disable */ /*eslint-disable */
import { useRef, useState } from "react"; import { useEffect, useRef, useState } from "react";
import { send } from "../Scripts/Testnet"; import { send } from "../Scripts/Testnet";
import sjcl from "sjcl"; import sjcl from "sjcl";
import { getFee } from "../Scripts/Testnet";
function desprorr2(encripted) { function desprorr2(encripted) {
var parsedMessage = JSON.parse(encripted); var parsedMessage = JSON.parse(encripted);
var encryptedMessageWithoutParameters = JSON.stringify(parsedMessage); var encryptedMessageWithoutParameters = JSON.stringify(parsedMessage);
@ -14,6 +15,10 @@ function desprorr2(encripted) {
} }
export default function Pay({ keys }) { export default function Pay({ keys }) {
const [comision, setComision] = useState("0"); const [comision, setComision] = useState("0");
const [fee, setFee] = useState("0");
useEffect(() => {
setFee(((parseFloat(getFee()) * 0.00001) / 100).toString());
}, []);
function calculatecomision() { function calculatecomision() {
let amount = document.getElementById("amount").value; let amount = document.getElementById("amount").value;
if (amount < 1) { if (amount < 1) {
@ -55,7 +60,10 @@ export default function Pay({ keys }) {
type="number" type="number"
onChange={calculatecomision} onChange={calculatecomision}
/> />
<p className="text-alert self-center text-sm">Comision: {comision}</p> <p className="text-alert self-center text-sm">
Comision BLC: {comision}
</p>
<p className="text-alert self-center text-sm">Comision XLM: {fee}</p>
</div> </div>
<label htmlFor="send2" className="font-bold text-3xl self-center"> <label htmlFor="send2" className="font-bold text-3xl self-center">
Extra comment: Extra comment:

View File

@ -16,6 +16,9 @@ export function getAddress(privatekey){
const keypair = StellarSdk.Keypair.fromSecret(privatekey) const keypair = StellarSdk.Keypair.fromSecret(privatekey)
return keypair.publicKey() return keypair.publicKey()
} }
export function getFee(){
return fee
}
export function send(amount, privatekey, destination, memo){ export function send(amount, privatekey, destination, memo){
if(memo === undefined || memo === null){ if(memo === undefined || memo === null){
memo = "."; memo = ".";