Skip to content

Commit 320ad68

Browse files
committed
ADDS validation in constructor for appId
1 parent 5576039 commit 320ad68

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/sdk/v4/NftSwapV4.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
getApprovalStatus,
3030
parseRawSignature,
3131
signOrderWithEoaWallet,
32+
verifyAppIdOrThrow,
3233
} from './pure';
3334
import type {
3435
AddressesForChainV4,
@@ -164,15 +165,23 @@ export interface AdditionalSdkConfig {
164165
}
165166

166167
class NftSwapV4 implements INftSwapV4 {
168+
// RPC provider
167169
public provider: BaseProvider;
170+
// Wallet signer
168171
public signer: Signer | undefined;
172+
// Chain Id for this instance of NftSwapV4.
173+
// To switch chains, instantiate a new version of NftSWapV4 with the updated chain id.
169174
public chainId: number;
170-
public exchangeProxy: IZeroEx;
175+
176+
// ZeroEx ExchangeProxy contract address to reference
171177
public exchangeProxyContractAddress: string;
178+
// Generated ZeroEx ExchangeProxy contracts
179+
public exchangeProxy: IZeroEx;
172180

173181
// Unique identifier for app. Must be a positive integer between 1 and 2**128
174182
public appId: string;
175183

184+
// Orderbook URL
176185
public orderbookRootUrl: string;
177186

178187
constructor(
@@ -204,6 +213,7 @@ class NftSwapV4 implements INftSwapV4 {
204213
additionalConfig?.orderbookRootUrl ?? ORDERBOOK_API_ROOT_URL_PRODUCTION;
205214

206215
this.appId = additionalConfig?.appId ?? DEFAULT_APP_ID;
216+
verifyAppIdOrThrow(this.appId);
207217

208218
this.exchangeProxy = IZeroEx__factory.connect(
209219
zeroExExchangeContractAddress,

src/sdk/v4/pure.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ const RESERVED_APP_ID_PREFIX_DIGITS = RESERVED_APP_ID_PREFIX.length;
399399

400400
export const DEFAULT_APP_ID = '314159';
401401

402-
const verifyAppIdOrThrow = (appId: string) => {
402+
export const verifyAppIdOrThrow = (appId: string) => {
403403
const isCorrectLength =
404404
appId.length <= ONE_TWENTY_EIGHT_BIT_LENGTH - RESERVED_APP_ID_PREFIX_DIGITS;
405405
const hasOnlyNumbers = checkIfStringContainsOnlyNumbers(appId);

0 commit comments

Comments
 (0)