Skip to content
Open
Show file tree
Hide file tree
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
23 changes: 17 additions & 6 deletions src/apis/contracts_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
ERC721_COLLATERALIZED_SIMPLE_INTEREST_TERMS_CONTRACT_CACHE_KEY,
ERC721_COLLATERALIZER_CONTRACT_CACHE_KEY,
ERC721_TOKEN_REGISTRY_CONTRACT_CACHE_KEY,
MINTABLE_ERC721_CACHE_KEY,
NULL_ADDRESS,
REPAYMENT_ROUTER_CONTRACT_CACHE_KEY,
SIMPLE_INTEREST_TERMS_CONTRACT_CACHE_KEY,
Expand Down Expand Up @@ -329,18 +330,28 @@ export class ContractsAPI {
public async loadMintableERC721ContractAsync(
transactionOptions: object = {},
): Promise<MintableERC721TokenContract> {
const cacheKey = "MintableERC721TokenContract";
if (MINTABLE_ERC721_CACHE_KEY in this.cache) {
return this.cache[MINTABLE_ERC721_CACHE_KEY] as MintableERC721TokenContract;
}

if (cacheKey in this.cache) {
return this.cache[cacheKey] as MintableERC721TokenContract;
let mintableERC721: MintableERC721TokenContract;

if (this.addressBook.mintableERC721Address) {
mintableERC721 = await MintableERC721TokenContract.at(
this.addressBook.mintableERC721Address,
this.web3,
transactionOptions,
);
} else {
const tokenContract = await MintableERC721TokenContract.deployed(
mintableERC721 = await MintableERC721TokenContract.deployed(
this.web3,
transactionOptions,
);
this.cache[cacheKey] = tokenContract;
return tokenContract;
}

this.cache[MINTABLE_ERC721_CACHE_KEY] = mintableERC721;

return mintableERC721;
}

public async loadERC721ContractAsync(
Expand Down
1 change: 1 addition & 0 deletions src/types/address_book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export interface AddressBook {
erc721TokenRegistryContract?: string;
erc721CollateralizerAddress?: string;
collateralizerAddress?: string;
mintableERC721Address?: string;
}
1 change: 1 addition & 0 deletions utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const ERC721_COLLATERALIZER_CONTRACT_CACHE_KEY = "ERC721CollateralizerCon
export const ERC721_COLLATERALIZED_SIMPLE_INTEREST_TERMS_CONTRACT_CACHE_KEY =
"ERC721CollateralizedSimpleInterestTermsContract";
export const ERC721_TOKEN_REGISTRY_CONTRACT_CACHE_KEY = "ERC721TokenRegistryContract";
export const MINTABLE_ERC721_CACHE_KEY = "MintableERC721TokenContract";

export const TERMS_CONTRACT_TYPES = {
COLLATERALIZED_SIMPLE_INTEREST_LOAN: "CollateralizedSimpleInterestLoan",
Expand Down