Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export const ServerAccess: React.FC<ServerAccessProps> = ({ onComplete }) => {

const { walletBalances } = useWallet();
const MIN_BALANCE = 5_000_000;
const hasEnoughBalance = (walletBalances?.uakt || 0) >= MIN_BALANCE;
const hasEnoughBalance = walletBalances !== null && (walletBalances.uakt || 0) >= MIN_BALANCE;
const isBalanceLoaded = walletBalances !== null;

// Define calculateNodeCounts before using it in useEffect
const calculateNodeCounts = useCallback((totalNodes: number) => {
Expand All @@ -37,10 +38,10 @@ export const ServerAccess: React.FC<ServerAccessProps> = ({ onComplete }) => {
}, []);

React.useEffect(() => {
if (!hasEnoughBalance) {
if (isBalanceLoaded && !hasEnoughBalance) {
setShowBalancePopup(true);
}
}, [hasEnoughBalance]);
}, [hasEnoughBalance, isBalanceLoaded]);

// Initialize server configs whenever number of servers changes or we activate server form
React.useEffect(() => {
Expand Down Expand Up @@ -97,12 +98,15 @@ export const ServerAccess: React.FC<ServerAccessProps> = ({ onComplete }) => {
}, []);

const handleNextClick = useCallback(() => {
if (!isBalanceLoaded) {
return;
}
if (!hasEnoughBalance) {
setShowBalancePopup(true);
return;
}
setShowNodeDistribution(true);
}, [hasEnoughBalance]);
}, [hasEnoughBalance, isBalanceLoaded]);
Comment thread
jigar-arc10 marked this conversation as resolved.

const handleDistributionNext = useCallback(() => {
setShowNodeDistribution(false);
Expand Down Expand Up @@ -137,8 +141,11 @@ export const ServerAccess: React.FC<ServerAccessProps> = ({ onComplete }) => {
</div>
<div className="flex w-full justify-between">
<div className="flex justify-start"></div>
<div className="flex justify-end">
<Button onClick={handleNextClick}>Next</Button>
<div className="flex flex-col items-end gap-2">
{!isBalanceLoaded && <p className="text-muted-foreground text-sm">Loading wallet balance...</p>}
<Button onClick={handleNextClick} disabled={!isBalanceLoaded}>
Next
</Button>
</div>
</div>
</div>
Expand Down
Loading