Skip to content

Commit

Permalink
fix antipatterns
Browse files Browse the repository at this point in the history
  • Loading branch information
H34D committed Jun 12, 2023
1 parent 48320a2 commit 20951fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
13 changes: 10 additions & 3 deletions src/modules/account/get-balances.ts
Expand Up @@ -39,6 +39,7 @@ export const getBalances = async (
userAddress: string,
tokenAddress?: string
): Promise<number | undefined> => {
let result;
if (
!masa.config.signer.provider ||
!tokenAddress ||
Expand All @@ -58,24 +59,28 @@ export const getBalances = async (
contract.decimals(),
]);

return parseFloat(utils.formatUnits(balance, decimals));
result = parseFloat(utils.formatUnits(balance, decimals));
} catch (error: unknown) {
if (error instanceof Error) {
console.error(
`Token: ${tokenAddress} Wallet Address: ${addressToLoad} ${error.message}`
);
}
}

return result;
};

const loadSBTContractBalance = async (
contract: SBTContracts,
addressToLoad: string
): Promise<number | undefined> => {
if (contract.address === constants.AddressZero) return;
let result;

if (contract.address === constants.AddressZero) return result;

try {
return (await contract.balanceOf(addressToLoad)).toNumber();
result = (await contract.balanceOf(addressToLoad)).toNumber();
} catch (error: unknown) {
if (error instanceof Error) {
console.error(
Expand All @@ -87,6 +92,8 @@ export const getBalances = async (
);
}
}

return result;
};

let ERC20Balances;
Expand Down
9 changes: 6 additions & 3 deletions src/modules/identity/load.ts
Expand Up @@ -77,13 +77,16 @@ export const loadIdentity = async (
masa: MasaInterface,
address?: string
): Promise<IdentityDetails | undefined> => {
let result;

address = address || (await masa.config.signer.getAddress());

const { identityId } = await masa.identity.load(address);
if (!identityId) {
if (identityId) {
result = await loadIdentityDetails(masa, identityId);
} else {
console.error(Messages.NoIdentity(address));
return;
}

return loadIdentityDetails(masa, identityId);
return result;
};

0 comments on commit 20951fd

Please sign in to comment.