diff --git a/cli/src/cli-helpers/ensureBalances.ts b/cli/src/cli-helpers/ensureBalances.ts index 24d38adb..722edb0c 100644 --- a/cli/src/cli-helpers/ensureBalances.ts +++ b/cli/src/cli-helpers/ensureBalances.ts @@ -8,11 +8,13 @@ export async function ensureBalances({ iexec, nRlcMin, weiMin, + warnOnlyRlc = false, }: { spinner: Spinner; iexec: IExec; nRlcMin?: BN; weiMin?: BN; + warnOnlyRlc?: boolean; }): Promise<{ wei: BN; nRLC: BN; @@ -34,15 +36,7 @@ export async function ensureBalances({ (chainId !== 134 && totalRlc.isZero()) || (!!nRlcMin && totalRlc.lt(nRlcMin)); - if (!missingNative && !missingRlc) { - return { - wei, - nRLC, - stake, - }; - } - - const helpers = []; + // Always check native assets - they're required for transaction fees if (missingNative) { const msg = wei.isZero() ? ' - Native balance is empty' @@ -50,29 +44,64 @@ export async function ensureBalances({ const requirement = weiMin ? ` (requires ${utils.formatEth(weiMin as BN)} ether)` : ''; - helpers.push(`${msg}${requirement}`); + + spinner.log( + warnBox(`Current chain requires native asset to pay transaction fees! + +Your wallet balance is insufficient: +${msg}${requirement} + +You can either: + - Fund your wallet ${emphasis(address)} + - Import another wallet (run ${command('iapp wallet import')}) + - Select an imported wallet (run ${command('iapp wallet select')}) + - Use another chain (use option ${command('--chain ')})`) + ); + throw Error(`Native balance is insufficient`); } + + // For RLC, either warn only or block based on warnOnlyRlc option if (missingRlc) { - const msg = totalRlc.isZero() - ? ' - RLC balance is empty' - : ' - RLC balance is insufficient'; - const requirement = nRlcMin - ? ` (requires ${utils.formatRLC(nRlcMin as BN)} RLC)` - : ''; - helpers.push(`${msg}${requirement}`); - } + if (warnOnlyRlc) { + // Just warn for RLC, don't block + const msg = totalRlc.isZero() + ? ' - RLC balance is empty' + : ' - RLC balance is insufficient'; + const requirement = nRlcMin + ? ` (requires ${utils.formatRLC(nRlcMin as BN)} RLC)` + : ''; + + spinner.warn( + `⚠️ Warning: Your wallet has insufficient RLC balance:${msg}${requirement}. You'll need RLC to run your iApp later. Consider funding your wallet ${emphasis(address)} or importing another wallet.` + ); + } else { + // Block for RLC (original behavior) + const msg = totalRlc.isZero() + ? ' - RLC balance is empty' + : ' - RLC balance is insufficient'; + const requirement = nRlcMin + ? ` (requires ${utils.formatRLC(nRlcMin as BN)} RLC)` + : ''; - spinner.log( - warnBox(`Current chain requires ${chainId !== 134 ? 'native asset to pay transaction fees and ' : ''}RLC to pay iApp runs! + spinner.log( + warnBox(`Current chain requires RLC to pay iApp runs! Your wallet balance is insufficient: -${helpers.join('\n')} +${msg}${requirement} You can either: - Fund your wallet ${emphasis(address)} - Import another wallet (run ${command('iapp wallet import')}) - Select an imported wallet (run ${command('iapp wallet select')}) - Use another chain (use option ${command('--chain ')})`) - ); - throw Error(`Balance is insufficient`); + ); + throw Error(`RLC balance is insufficient`); + } + } + + return { + wei, + nRLC, + stake, + }; } diff --git a/cli/src/cmd/deploy.ts b/cli/src/cmd/deploy.ts index 97b92df9..4792b280 100644 --- a/cli/src/cmd/deploy.ts +++ b/cli/src/cmd/deploy.ts @@ -46,7 +46,8 @@ export async function deploy({ chain }: { chain?: string }) { iexec = getIExec({ ...chainConfig, signer }); } - await ensureBalances({ spinner, iexec }); + // Check balances: always verify native assets for transaction fees, but only warn for RLC + await ensureBalances({ spinner, iexec, warnOnlyRlc: true }); const dockerhubUsername = await askForDockerhubUsername({ spinner }); const dockerhubAccessToken = await askForDockerhubAccessToken({ spinner });