);
};
// Interesting, this seems to need to be above the StakeUnstakeWithdrawModal declaration
const walletUnstake = ({ validator, amount }) => {
setStakingModalData({ validator, method: "unstake", amount });
setShowStakingModal(true);
};
const walletWithdraw = ({ validator, amount }) => {
console.log('aloha walletWithdraw amount', amount);
setStakingModalData({ validator, method: "withdraw" });
setShowStakingModal(true);
};
const walletStake = ({ validator, amount }) => {
console.log('aloha stake validator', validator)
setStakingModalData({ validator, method: "stake", amount });
setShowStakingModal(true);
};
// State initialization
const [progressVal, setProgressVal] = useState(0);
const [progressMax, setProgressMax] = useState(1_000);
const [started, setStarted] = useState(false);
const [showProgressBar, setShowProgressBar] = useState(true);
const [validatorStakingDetails, setValidatorStakingDetails] = useState([]);
const [isLoading, setIsLoading] = useState(true);
const [showStakingModal, setShowStakingModal] = useState(false);
const [stakingModalData, setStakingModalData] = useState(false);
const YOCTO_DIGITS = 24;
// being modified from near-js utils
function cleanupAmount(amt) {
// Remove commas by splitting on them and joining the parts back together
return amt.split(",").join("").trim();
}
function trimLeadingZeroes(str) {
// Find the first non-zero character
let firstNonZeroIndex = 0;
while (firstNonZeroIndex < str.length && str[firstNonZeroIndex] === "0") {
firstNonZeroIndex++;
}
// Return the substring from the first non-zero character or '0' if all characters were zeroes
return firstNonZeroIndex === str.length
? "0"
: str.substring(firstNonZeroIndex);
}
function parseNearAmount(amt) {
if (!amt) {
return null;
}
amt = cleanupAmount(amt);
const split = amt.split(".");
const wholePart = split[0];
const fracPart = split[1] || "";
// Check for valid format
if (split.length > 2 || fracPart.length > YOCTO_DIGITS) {
throw new Error(`Cannot parse '${amt}' as NEAR amount`);
}
// Combine the whole part and the fractional part padded to NEAR_NOMINATION_EXP length
return trimLeadingZeroes(wholePart + fracPart.padEnd(YOCTO_DIGITS, "0"));
}
// end modified from near-js utils
// this is a strange function that'll help with removing the modal nicely
// seems to be somewhat a BOS-related piquant feature
useEffect(async () => {
if (progressVal >= progressMax) {
const timer = setTimeout(() => setIsLoading(false), 300);
return () => clearTimeout(timer);
}
}, [progressVal, progressMax]);
const LoadingModal = () => {
// This helps with the flash of red if it hasn't loaded yet
if (!!!ProgressBar) {
return <>>;
} else {
if (!!!context.accountId) {
console.log("(BOS variable) context.accountId not ready");
return;
}
return (