Skip to content

Commit 9d31318

Browse files
fix: stop blocking iapp deploy when RLC balance is empty
1 parent d671467 commit 9d31318

File tree

2 files changed

+41
-32
lines changed

2 files changed

+41
-32
lines changed
Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import { warnBox } from './box.js';
2-
import { emphasis, command } from './color.js';
2+
import { emphasis, command, promptHelper } from './color.js';
33
import type { Spinner } from './spinner.js';
44
import { BN, IExec, utils } from 'iexec';
55

66
export async function ensureBalances({
77
spinner,
88
iexec,
9+
warnOnlyRlc = false,
910
nRlcMin,
1011
weiMin,
1112
}: {
1213
spinner: Spinner;
1314
iexec: IExec;
15+
warnOnlyRlc?: boolean;
1416
nRlcMin?: BN;
1517
weiMin?: BN;
1618
}): Promise<{
@@ -34,36 +36,33 @@ export async function ensureBalances({
3436
(chainId !== 134 && totalRlc.isZero()) ||
3537
(!!nRlcMin && totalRlc.lt(nRlcMin));
3638

37-
if (!missingNative && !missingRlc) {
38-
return {
39-
wei,
40-
nRLC,
41-
stake,
42-
};
43-
}
39+
const shouldThrow = missingNative || (missingRlc && !warnOnlyRlc);
4440

45-
const helpers = [];
46-
if (missingNative) {
47-
const msg = wei.isZero()
48-
? ' - Native balance is empty'
49-
: ' - Native balance is insufficient';
50-
const requirement = weiMin
51-
? ` (requires ${utils.formatEth(weiMin as BN)} ether)`
52-
: '';
53-
helpers.push(`${msg}${requirement}`);
54-
}
55-
if (missingRlc) {
56-
const msg = totalRlc.isZero()
57-
? ' - RLC balance is empty'
58-
: ' - RLC balance is insufficient';
59-
const requirement = nRlcMin
60-
? ` (requires ${utils.formatRLC(nRlcMin as BN)} RLC)`
61-
: '';
62-
helpers.push(`${msg}${requirement}`);
63-
}
41+
// always show missing balance warnings
42+
if (missingNative || missingRlc) {
43+
const helpers = [];
44+
if (missingNative) {
45+
const msg =
46+
' - Native asset balance required for blockchain transactions is ' +
47+
(wei.isZero() ? 'empty' : 'insufficient');
48+
const requirement = weiMin
49+
? ` (requires ${utils.formatEth(weiMin as BN)} ether)`
50+
: '';
51+
helpers.push(`${msg}${requirement}`);
52+
}
53+
if (missingRlc) {
54+
const msg =
55+
' - RLC token balance required for iapp runs is ' +
56+
(totalRlc.isZero() ? 'empty' : 'insufficient') +
57+
(warnOnlyRlc ? promptHelper(' (warning only)') : '');
58+
const requirement = nRlcMin
59+
? ` (requires ${utils.formatRLC(nRlcMin as BN)} RLC)`
60+
: '';
61+
helpers.push(`${msg}${requirement}`);
62+
}
6463

65-
spinner.log(
66-
warnBox(`Current chain requires ${chainId !== 134 ? 'native asset to pay transaction fees and ' : ''}RLC to pay iApp runs!
64+
spinner.log(
65+
warnBox(`Current chain requires ${chainId !== 134 ? 'native asset to pay transaction fees and ' : ''}RLC to pay iApp runs!
6766
6867
Your wallet balance is insufficient:
6968
${helpers.join('\n')}
@@ -73,6 +72,16 @@ You can either:
7372
- Import another wallet (run ${command('iapp wallet import')})
7473
- Select an imported wallet (run ${command('iapp wallet select')})
7574
- Use another chain (use option ${command('--chain <name>')})`)
76-
);
77-
throw Error(`Balance is insufficient`);
75+
);
76+
}
77+
78+
if (shouldThrow) {
79+
throw Error(`Balance is insufficient`);
80+
}
81+
82+
return {
83+
wei,
84+
nRLC,
85+
stake,
86+
};
7887
}

cli/src/cmd/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export async function deploy({ chain }: { chain?: string }) {
4646
iexec = getIExec({ ...chainConfig, signer });
4747
}
4848

49-
await ensureBalances({ spinner, iexec });
49+
await ensureBalances({ spinner, iexec, warnOnlyRlc: true });
5050

5151
const dockerhubUsername = await askForDockerhubUsername({ spinner });
5252
const dockerhubAccessToken = await askForDockerhubAccessToken({ spinner });

0 commit comments

Comments
 (0)