Skip to content

Commit d630396

Browse files
committed
refactor: remove nested ternary operator
1 parent fa2aad3 commit d630396

File tree

2 files changed

+36
-28
lines changed

2 files changed

+36
-28
lines changed

contracts/deploy/00-home-chain-arbitration.ts

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { HardhatRuntimeEnvironment } from "hardhat/types";
2-
import { DeployFunction } from "hardhat-deploy/types";
2+
import { DeployFunction, DeployResult } from "hardhat-deploy/types";
33
import { BigNumber } from "ethers";
44
import getContractAddress from "../deploy-helpers/getContractAddress";
55
import { VRFSubscriptionManagerV2, VRFSubscriptionManagerV2Mock } from "../typechain-types";
@@ -151,19 +151,23 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
151151
const numWords = 1;
152152
const vrfCoordinator = vrfCoordinatorByChain.get(Number(await getChainId())) ?? AddressZero;
153153
// Deploy the VRF Subscription Manager contract on Arbitrum, a mock contract on Hardhat node or nothing on other networks.
154-
const vrfSubscriptionManager = vrfCoordinator
155-
? chainId === HomeChains.HARDHAT
156-
? await deploy("VRFSubscriptionManagerV2Mock", {
157-
from: deployer,
158-
args: [deployer, vrfCoordinator],
159-
log: true,
160-
})
161-
: await deploy("VRFSubscriptionManagerV2", {
162-
from: deployer,
163-
args: [deployer, vrfCoordinator, link],
164-
log: true,
165-
})
166-
: AddressZero;
154+
let vrfSubscriptionManager: DeployResult | string;
155+
if (vrfCoordinator) {
156+
vrfSubscriptionManager =
157+
chainId === HomeChains.HARDHAT
158+
? await deploy("VRFSubscriptionManagerV2Mock", {
159+
from: deployer,
160+
args: [deployer, vrfCoordinator],
161+
log: true,
162+
})
163+
: await deploy("VRFSubscriptionManagerV2", {
164+
from: deployer,
165+
args: [deployer, vrfCoordinator, link],
166+
log: true,
167+
});
168+
} else {
169+
vrfSubscriptionManager = AddressZero;
170+
}
167171

168172
// Execute the setup transactions for using VRF and deploy the Consumer contract on Hardhat node
169173
// The Sortition Module rng source is not changed to the VRF Consumer.

contracts/deploy/00-rng.ts

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { BigNumber } from "ethers";
3-
import { DeployFunction } from "hardhat-deploy/types";
3+
import { DeployFunction, DeployResult } from "hardhat-deploy/types";
44
import { SortitionModule, VRFSubscriptionManagerV2Mock, VRFSubscriptionManagerV2 } from "../typechain-types";
55

66
enum HomeChains {
@@ -99,19 +99,23 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
9999
const numWords = 1;
100100
const vrfCoordinator = vrfCoordinatorByChain.get(Number(await getChainId())) ?? AddressZero;
101101
// Deploy the VRF Subscription Manager contract on Arbitrum, a mock contract on Hardhat node or nothing on other networks.
102-
const vrfSubscriptionManager = vrfCoordinator
103-
? chainId === HomeChains.HARDHAT
104-
? await deploy("VRFSubscriptionManagerV2Mock", {
105-
from: deployer,
106-
args: [deployer, vrfCoordinator],
107-
log: true,
108-
})
109-
: await deploy("VRFSubscriptionManagerV2", {
110-
from: deployer,
111-
args: [deployer, vrfCoordinator, link],
112-
log: true,
113-
})
114-
: AddressZero;
102+
let vrfSubscriptionManager: DeployResult | string;
103+
if (vrfCoordinator) {
104+
vrfSubscriptionManager =
105+
chainId === HomeChains.HARDHAT
106+
? await deploy("VRFSubscriptionManagerV2Mock", {
107+
from: deployer,
108+
args: [deployer, vrfCoordinator],
109+
log: true,
110+
})
111+
: await deploy("VRFSubscriptionManagerV2", {
112+
from: deployer,
113+
args: [deployer, vrfCoordinator, link],
114+
log: true,
115+
});
116+
} else {
117+
vrfSubscriptionManager = AddressZero;
118+
}
115119

116120
// Execute the setup transactions for using VRF and deploy the Consumer contract on Hardhat node
117121
// The Sortition Module rng source is not changed to the VRF Consumer.

0 commit comments

Comments
 (0)