Skip to content

Commit

Permalink
Merge pull request #753 from hubiinetwork/feature/1.0.0-beta.3-fix
Browse files Browse the repository at this point in the history
Fix a bug when there is no corresponding asset between base layer and nahmii
  • Loading branch information
katat committed Apr 18, 2019
2 parents b59cba3 + 1a33e30 commit b7ab4ba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
24 changes: 15 additions & 9 deletions src/containers/NahmiiWithdraw/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ export class NahmiiWithdraw extends React.Component { // eslint-disable-line rea
constructor(props) {
super(props);

const baseLayerAssets = props.currentWalletWithInfo.getIn(['balances', 'baseLayer', 'assets']).toJS();
const assetToWithdraw = baseLayerAssets[0] || { symbol: 'ETH', currency: '0x0000000000000000000000000000000000000000', balance: new BigNumber('0') };
const nahmiiCombinedAssets = props.currentWalletWithInfo.getIn(['balances', 'nahmiiCombined', 'assets']).toJS();
const assetToWithdraw = nahmiiCombinedAssets[0] || { symbol: 'ETH', currency: '0x0000000000000000000000000000000000000000', balance: new BigNumber('0') };

// max decimals possible for current asset
let assetToWithdrawMaxDecimals = 18;
Expand Down Expand Up @@ -128,8 +128,8 @@ export class NahmiiWithdraw extends React.Component { // eslint-disable-line rea
const { assetToWithdraw } = this.state;
const { currentWalletWithInfo } = this.props;

const baseLayerAssets = currentWalletWithInfo.getIn(['balances', 'baseLayer', 'assets']).toJS();
const asset = baseLayerAssets.find((a) => a.symbol === assetToWithdraw.symbol);
const nahmiiCombinedAssets = currentWalletWithInfo.getIn(['balances', 'nahmiiCombined', 'assets']).toJS();
const asset = nahmiiCombinedAssets.find((a) => a.symbol === assetToWithdraw.symbol);
if (asset && asset.balance.toString() !== assetToWithdraw.balance.toString()) {
assetToWithdraw.balance = asset.balance;
}
Expand Down Expand Up @@ -208,8 +208,8 @@ export class NahmiiWithdraw extends React.Component { // eslint-disable-line rea

handleAssetChange(newSymbol) {
const { currentWalletWithInfo, supportedAssets } = this.props;
const baseLayerAssets = currentWalletWithInfo.getIn(['balances', 'baseLayer', 'assets']).toJS();
const assetToWithdraw = baseLayerAssets.find((a) => a.symbol === newSymbol);
const nahmiiCombinedAssets = currentWalletWithInfo.getIn(['balances', 'nahmiiCombined', 'assets']).toJS();
const assetToWithdraw = nahmiiCombinedAssets.find((a) => a.symbol === newSymbol);

// max decimals possible for current asset
const assetToWithdrawMaxDecimals = supportedAssets
Expand Down Expand Up @@ -438,6 +438,7 @@ export class NahmiiWithdraw extends React.Component { // eslint-disable-line rea
}

const baseLayerAssets = currentWalletWithInfo.getIn(['balances', 'baseLayer', 'assets']).toJS();
const nahmiiCombinedAssets = currentWalletWithInfo.getIn(['balances', 'nahmiiCombined', 'assets']).toJS();
const nahmiiStagedAssets = currentWalletWithInfo.getIn(['balances', 'nahmiiStaged', 'assets']).toJS();

const nahmiiAssets = currentWalletWithInfo.getIn(['balances', 'nahmiiAvailable', 'assets']).toJS();
Expand All @@ -459,9 +460,14 @@ export class NahmiiWithdraw extends React.Component { // eslint-disable-line rea
};

// construct asset before and after balances
const baseLayerAsset = baseLayerAssets.find((a) => a.symbol === assetToWithdraw.symbol) || {
symbol: assetToWithdraw.symbol,
currency: assetToWithdraw.currency,
balance: new BigNumber('0'),
};
const baseLayerBalanceBefore = {
amount: assetToWithdraw.balance,
usdValue: assetToWithdraw.balance.times(assetToWithdrawUsdValue),
amount: baseLayerAsset.balance,
usdValue: baseLayerAsset.balance.times(assetToWithdrawUsdValue),
};
const nahmiiBalanceBeforeAmt = (nahmiiAssets
.find((asset) => asset.currency === assetToWithdraw.currency) || { balance: new BigNumber('0') })
Expand Down Expand Up @@ -554,7 +560,7 @@ export class NahmiiWithdraw extends React.Component { // eslint-disable-line rea
onSelect={this.handleAssetChange}
style={{ paddingLeft: '0.5rem' }}
>
{baseLayerAssets.map((currency) => (
{nahmiiCombinedAssets.map((currency) => (
<Option value={currency.symbol} key={currency.symbol}>
{currency.symbol}
</Option>
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11143,10 +11143,10 @@ nahmii-contract-abstractions-ropsten@1.3.0:
resolved "https://registry.yarnpkg.com/nahmii-contract-abstractions-ropsten/-/nahmii-contract-abstractions-ropsten-1.3.0.tgz#0966c377de4c350a7e0714b8d5ffa40da0b36335"
integrity sha512-su1t+f66K9bDejTLLN+wr0nNRgy56FZDvSptamenR7EgBK3tEtfcoE3F3K17wdRNQCs3xKFlWTyHcBVnGZZFrA==

nahmii-contract-abstractions@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/nahmii-contract-abstractions/-/nahmii-contract-abstractions-1.0.0.tgz#df26ac3dcf60d5f7a7bdf15cfd2809c15e34f28a"
integrity sha512-t/iRligdjC9yRz7/4cS7QqJOCQqKJbh+yvybhqlJCuMkQo1D4cB/KxcaZGJqjyDxfFXBTJOY4Vp83psKTE53sQ==
nahmii-contract-abstractions@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/nahmii-contract-abstractions/-/nahmii-contract-abstractions-1.1.1.tgz#3a8582412c6d776565e0e11e1c1d7db4ccbb2c18"
integrity sha512-blTe6LBCcjl2THW9m55zhoDZYWcKHlNBLfZFbJnrdvQNkNprmTAArf1OFuZYTK56mJsh49+Va3AE3w8NpWlU2Q==

nahmii-ethereum-address@^2.0.0:
version "2.0.0"
Expand All @@ -11155,15 +11155,15 @@ nahmii-ethereum-address@^2.0.0:
dependencies:
bson "^3.0.2"

nahmii-sdk@1.0.0-beta.48:
version "1.0.0-beta.48"
resolved "https://registry.yarnpkg.com/nahmii-sdk/-/nahmii-sdk-1.0.0-beta.48.tgz#12e2e6514ee5f17829f383ccd1c6d98e5354cfed"
integrity sha512-Kgd/1luNP5E9ZWNHeOPTEAEnl4Z4VURncvQHLwO8t5kBg5kcU1Mvv6rnbDwshpf2VHWikqnWSF+nj0kqMyPqgg==
nahmii-sdk@1.0.0-beta.49:
version "1.0.0-beta.49"
resolved "https://registry.yarnpkg.com/nahmii-sdk/-/nahmii-sdk-1.0.0-beta.49.tgz#cb7f8c1b8fafa3195fe7d66a3c397e9f3313577c"
integrity sha512-RnEyJjcXo8q6VraBTJ2C+/oxT5G6tVRAjWKdbdyCDizNYLZyDcwatDUQiAx/Dtfpof2ol2crxVErRkhiIT7/6g==
dependencies:
ethereumjs-util "^5.2.0"
keythereum "^1.0.4"
lodash.get "^4.4.2"
nahmii-contract-abstractions "1.0.0"
nahmii-contract-abstractions "1.1.1"
nahmii-contract-abstractions-ropsten "1.3.0"
nahmii-ethereum-address "^2.0.0"
node-yaml "^3.1.1"
Expand Down

0 comments on commit b7ab4ba

Please sign in to comment.