Skip to content

Commit

Permalink
refactor: AssetCard use helper for price data
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyAziz committed Aug 29, 2021
1 parent 45c67f6 commit 22c40c2
Showing 1 changed file with 17 additions and 49 deletions.
66 changes: 17 additions & 49 deletions lib/components/AssetCard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import moment from 'moment';
import {useNavigation} from '@react-navigation/native';
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';

import {Helpers} from '@lib/components/AssetDetails';

import Eth from '@lib/components/Eth';

import * as Styled from './styled';
Expand All @@ -14,9 +16,6 @@ import Web3 from 'web3';

const AssetCard = ({node}) => {
const navigation = useNavigation();
let saleType;
let lastSalePrice;
let bestBidPrice;

let assetBundle = node.assetBundle;

Expand All @@ -26,35 +25,18 @@ const AssetCard = ({node}) => {

let name = assetBundle ? node.assetBundle.name : node.asset.name;

let onSale = node[assetBundle ? 'assetBundle' : 'asset'].orderData.bestAsk;

if (onSale) {
saleType =
node[assetBundle ? 'assetBundle' : 'asset'].orderData.bestAsk.orderType;
}

let price = assetBundle
? node.assetBundle.orderData.bestAsk.paymentAssetQuantity.quantity
: node.asset.orderData.bestAsk
? node.asset.orderData.bestAsk.paymentAssetQuantity.quantity
: null;

let lastSale =
node[assetBundle ? 'assetBundle' : 'asset'].assetEventData.lastSale;

if (lastSale) {
lastSalePrice =
node[assetBundle ? 'assetBundle' : 'asset'].assetEventData.lastSale
.unitPriceQuantity.quantity;
}

let bestBid = node[assetBundle ? 'assetBundle' : 'asset'].orderData.bestBid;

if (bestBid) {
bestBidPrice =
node[assetBundle ? 'assetBundle' : 'asset'].orderData.bestBid
.paymentAssetQuantity.quantity;
}
let {
onSale,
price,
priceUSD,
saleType,
lastSale,
bestBid,
lastSalePrice,
lastSalePriceUSD,
bestBidPrice,
bestBidPriceUSD,
} = Helpers.getPriceInfo(node, assetBundle);

const navigate = () => {
ReactNativeHapticFeedback.trigger('impactHeavy');
Expand Down Expand Up @@ -82,11 +64,7 @@ const AssetCard = ({node}) => {
<Styled.PriceLabel>Price</Styled.PriceLabel>
<Styled.PriceContainer>
<Eth />
<Styled.Price>
{parseFloat(Web3.utils.fromWei(price, 'ether'), 10).toFixed(
2,
)}
</Styled.Price>
<Styled.Price>{price.toFixed(2)}</Styled.Price>
</Styled.PriceContainer>
</View>
)}
Expand All @@ -96,12 +74,7 @@ const AssetCard = ({node}) => {
<Styled.PriceLabel>Last</Styled.PriceLabel>
<Styled.PriceContainer>
<Eth />
<Styled.Price>
{parseFloat(
Web3.utils.fromWei(lastSalePrice, 'ether'),
10,
).toFixed(2)}
</Styled.Price>
<Styled.Price>{lastSalePrice.toFixed(2)}</Styled.Price>
</Styled.PriceContainer>
</View>
)}
Expand All @@ -110,12 +83,7 @@ const AssetCard = ({node}) => {
<Styled.PriceLabel>Best Bid</Styled.PriceLabel>
<Styled.PriceContainer>
<Eth />
<Styled.Price>
{parseFloat(
Web3.utils.fromWei(bestBidPrice, 'ether'),
10,
).toFixed(2)}
</Styled.Price>
<Styled.Price>{bestBidPrice.toFixed(2)}</Styled.Price>
</Styled.PriceContainer>
</View>
)}
Expand Down

0 comments on commit 22c40c2

Please sign in to comment.