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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from 'src/types/token';
import { hexaToASCII, ASCIIToHexa } from 'src/utils/hex';
import { checkSolidityBytes32 } from 'src/utils/solidity';
import { addNumbersByConvertingIntoBigNumber } from "src/utils/number";

@Injectable()
export class PartitionService {
Expand Down Expand Up @@ -281,10 +282,9 @@ export class PartitionService {
partitionClass
].reduce((supply: number, currentAssetState: AssetStateOnChainData) => {
return (
supply +
currentAssetState[
addNumbersByConvertingIntoBigNumber(supply, currentAssetState[
TokenKeys.ASSET_CLASSES_ON_CHAIN_STATES_TOTAL_SUPPLY
]
])
);
}, 0);
const assetClassOnChainData: AssetClassOnChainData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
DocumentKeys,
GeneralDataKeys,
} from 'src/types/asset';
import { addNumbersByConvertingIntoBigNumber } from "src/utils/number";

const funderAddress: string = process.env.FUNDER_ADDRESS;

Expand Down Expand Up @@ -427,8 +428,9 @@ export class TokenHelperService {
? assetClassesOnChainData.reduce(
(supply: number, assetClassData: AssetClassOnChainData) => {
return (
supply +
assetClassData[TokenKeys.ASSET_CLASSES_ON_CHAIN_TOTAL_SUPPLY]
addNumbersByConvertingIntoBigNumber(supply, assetClassData[
TokenKeys.ASSET_CLASSES_ON_CHAIN_STATES_TOTAL_SUPPLY
])
);
},
0,
Expand Down
29 changes: 28 additions & 1 deletion assets/services/assets-api/src/utils/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const MAX_SUPPORTED_INTEGER = 1000000000000000;
export const MIN_SUPPORTED_INTEGER = 0;

/**
* Function if integer is not to big in order to avoid 'overflow' in database
* Function if integer is not too big in order to avoid 'overflow' in database
*/
export const checkIntegerFormat = (
quantity: number,
Expand Down Expand Up @@ -95,3 +95,30 @@ export const addDecimalsAndConvertToHex = (number, decimals): string => {
throw new Error(`addDecimalsAndConvertToHex --> ${error.message}`);
}
};

/**
* [Add Numbers By Converting Into BigNumber]
*
* The purpose of this function is to add numbers after converting
* them to BigNumber and then return the Number
*
* This function is used everytime we add two numbers.
*
*/
export const addNumbersByConvertingIntoBigNumber = (number1, number2): number => {
try {
const number1Bn = new BigNumber(number1);
const number2Bn = new BigNumber(number2);
const sumBn = number1Bn.plus(number2Bn);
return parseFloat(sumBn.toString());
} catch (error) {
ErrorService.logAndThrowFunctionError(
error,
`Failed to add numbers ${number1} and ${number2} by converting to BigNumber first`,
'addNumbersByConvertingIntoBigNumber',
false,
500,
);
throw new Error(`addNumbersByConvertingIntoBigNumber --> ${error.message}`);
}
};