-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finance: use aragonAPI for React (#765)
Only contains the changes needed to support aragonAPI for React: this is not a full conversion to React Hooks.
- Loading branch information
Showing
14 changed files
with
134 additions
and
218 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,66 @@ | ||
import BN from 'bn.js' | ||
import { ETHER_TOKEN_FAKE_ADDRESS } from './lib/token-utils' | ||
|
||
// Use this function to sort by ETH and then token symbol | ||
const compareBalancesByEthAndSymbol = (tokenA, tokenB) => { | ||
if (tokenA.address === ETHER_TOKEN_FAKE_ADDRESS) { | ||
return -1 | ||
} | ||
if (tokenB.address === ETHER_TOKEN_FAKE_ADDRESS) { | ||
return 1 | ||
} | ||
return tokenA.symbol.localeCompare(tokenB.symbol) | ||
} | ||
|
||
function appStateReducer(state) { | ||
const { balances, transactions } = state || {} | ||
|
||
const balancesBn = balances | ||
? balances | ||
.map(balance => ({ | ||
...balance, | ||
amount: new BN(balance.amount), | ||
decimals: new BN(balance.decimals), | ||
|
||
// Note that numbers in `numData` are not safe for accurate | ||
// computations (but are useful for making divisions easier). | ||
numData: { | ||
amount: parseInt(balance.amount, 10), | ||
decimals: parseInt(balance.decimals, 10), | ||
}, | ||
})) | ||
.sort(compareBalancesByEthAndSymbol) | ||
: [] | ||
|
||
const transactionsBn = transactions | ||
? transactions.map(transaction => ({ | ||
...transaction, | ||
amount: new BN(transaction.amount), | ||
numData: { | ||
amount: parseInt(transaction.amount, 10), | ||
}, | ||
})) | ||
: [] | ||
|
||
return { | ||
...state, | ||
|
||
tokens: balancesBn.map( | ||
({ address, name, symbol, numData: { amount, decimals }, verified }) => ({ | ||
address, | ||
amount, | ||
decimals, | ||
name, | ||
symbol, | ||
verified, | ||
}) | ||
), | ||
|
||
// Filter out empty balances | ||
balances: balancesBn.filter(balance => !balance.amount.isZero()), | ||
|
||
transactions: transactionsBn, | ||
} | ||
} | ||
|
||
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 was deleted.
Oops, something went wrong.
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.