Skip to content

Commit

Permalink
better code in schemeName function (#2370)
Browse files Browse the repository at this point in the history
  • Loading branch information
roienatan authored Dec 23, 2020
1 parent 858cdf7 commit 089087b
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions src/lib/schemeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,31 +71,11 @@ export const PROPOSAL_SCHEME_NAMES = [
"GenericSchemeMultiCall",
];

// /**
// * return true if the address is the address of a known scheme (which we know how to represent)
// * @param address [description]
// * @return [description]
// */
// export function isKnownScheme(address: Address) {
// const arc = getArc();
// let contractInfo;
// try {
// contractInfo = arc.getContractInfo(address);
// } catch (err) {
// if (err.message.match(/no contract/i)) {
// return false;
// }
// throw err;
// }

// if (KNOWN_SCHEME_NAMES.includes(contractInfo.name)) {
// return true;
// } else {
// return false;
// }
// }

export function schemeName(scheme: ISchemeState|IContractInfo, fallback?: string) {
if (!scheme) {
return undefined;
}
let name: string;
const contractInfo = (scheme as IContractInfo).alias ? scheme as IContractInfo : getArcByAddress(scheme.address)?.getContractInfo(scheme.address);

Expand All @@ -113,7 +93,9 @@ export function schemeName(scheme: ISchemeState|IContractInfo, fallback?: string
} else {
contractToCall = schemeState.uGenericSchemeParams.contractToCall;
}
const genericSchemeInfo = genericSchemeRegistry.getSchemeInfo(contractToCall, getNetworkByDAOAddress(schemeState.dao));

const network = getNetworkByDAOAddress(typeof schemeState.dao === "string" ? schemeState.dao : (schemeState.dao as any).id);
const genericSchemeInfo = genericSchemeRegistry.getSchemeInfo(contractToCall, network);
if (genericSchemeInfo) {
name = genericSchemeInfo.specs.name;
} else {
Expand Down

0 comments on commit 089087b

Please sign in to comment.