Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
186 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import BN from 'bn.js' | ||
import { map } from 'rxjs/operators' | ||
import { hasLoadedTokenSettings } from './token-settings' | ||
|
||
// Convert tokenSupply and holders balances to BNs, | ||
// and calculate tokenDecimalsBase. | ||
function appStateReducer(state) { | ||
const appStateReady = hasLoadedTokenSettings(state) | ||
if (!appStateReady) { | ||
return { | ||
...state, | ||
appStateReady, | ||
} | ||
} | ||
|
||
const { | ||
holders, | ||
maxAccountTokens, | ||
tokenDecimals, | ||
tokenSupply, | ||
tokenTransfersEnabled, | ||
} = state | ||
|
||
const tokenDecimalsBase = new BN(10).pow(new BN(tokenDecimals)) | ||
|
||
return { | ||
...state, | ||
appStateReady, | ||
tokenDecimalsBase, | ||
|
||
// Note that numbers in `numData` are not safe for accurate computations | ||
// (but are useful for making divisions easier) | ||
numData: { | ||
tokenDecimals: parseInt(tokenDecimals, 10), | ||
tokenSupply: parseInt(tokenSupply, 10), | ||
}, | ||
holders: holders | ||
? holders | ||
.map(holder => ({ ...holder, balance: new BN(holder.balance) })) | ||
.sort((a, b) => b.balance.cmp(a.balance)) | ||
: [], | ||
tokenDecimals: new BN(tokenDecimals), | ||
tokenSupply: new BN(tokenSupply), | ||
maxAccountTokens: new BN(maxAccountTokens), | ||
groupMode: tokenTransfersEnabled && maxAccountTokens === '1', | ||
} | ||
} | ||
|
||
export default appStateReducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.