Commit 8d03e0b3 by Nguyễn Thị Thúy

Merge branch 'phase2_home' into 'dev_phase2'

Phase2 home

See merge request !11
parents dc328c41 f362a5d6
import React, {useEffect, useState} from 'react'; import React, {useEffect, useState} from 'react';
import {View, Alert, Platform} from 'react-native'; import {Alert, Platform} from 'react-native';
import {connect} from 'react-redux'; import {connect} from 'react-redux';
import {getTransaction} from '../../apis/Functions/users'; import {getTransaction} from '../../apis/Functions/users';
import {getImagesHome} from '../../apis/Functions/General'; import {getImagesHome} from '../../apis/Functions/General';
import {getPriceTable} from '../../apis/Functions/Home';
import I18n from '../../helper/i18/i18n'; import I18n from '../../helper/i18/i18n';
import HomeView from './HomeView'; import HomeView from './HomeView';
import {getListCategoryProduct} from '../../apis/Functions/Transaction'; import {getListCategoryProduct} from '../../apis/Functions/Transaction';
import {hideLoading, showLoading} from '../../actions/loadingAction';
import _ from 'lodash';
const Home = (props) => { const Home = (props) => {
const [data, setData] = useState({total_deposit: 0, total_withdraw: 0}); const [data, setData] = useState({total_deposit: 0, total_withdraw: 0});
const [dataPrice, setDataPrice] = useState([ const [dataPrice, setDataPrice] = useState([]);
{ const [dataPriceFilter, setDataPriceFilter] = useState([]);
name: 'GCEM21', const [listImage, setListImage] = useState([]);
change: 0.2, const [filters, setFilters] = useState([]);
changePercent: 0.1, const [filterId, setFilterId] = useState(-1);
openPrice: 1777.2, useEffect(() => {
closePrice: 17778.3, getData();
highPrice: 1778.9, initSocket();
lowPrice: 1777, }, []);
time: 'Gold (Globex): June 2021', useEffect(() => {
isUp: false, const newList = filterId == -1 ? [...dataPrice] : _.filter([...dataPrice], item => item.category_id == filterId);
}, setDataPriceFilter(newList);
{ }, [dataPrice]);
name: 'GCEM21',
change: 0.5, const initSocket = () => {
changePercent: 0.1, let io = require('socket.io-client');
openPrice: 1777.2, let socket = io.connect('http://222.252.22.174:8087', {
closePrice: 17778.3, transports: ['websocket'],
highPrice: 1778.9, jsonp: false,
lowPrice: 1777, reconnect: true,
time: 'Gold (Globex): June 2021', });
isUp: true, socket.on('response-update-price', (message) => {
}, receivedMessage(message);
{ });
name: 'GCEM21', };
change: 0.1,
changePercent: 0.1, const receivedMessage = (message) => {
openPrice: 1777.2, setDataPrice(message);
closePrice: 17778.3, };
highPrice: 1778.9,
lowPrice: 1777, const getData = async () => {
time: 'Gold (Globex): June 2021', props.showLoading();
isUp: false, const res = await getTransaction({});
}, if (res.data.code == 200 && res.data.data) {
{ setData(res.data.data);
name: 'GCEM21', } else {
change: 0.6, Alert.alert(I18n.t('Notification'), I18n.t('Can_not_get_data'));
changePercent: 0.1, }
openPrice: 1777.2,
closePrice: 17778.3,
highPrice: 1778.9,
lowPrice: 1777,
time: 'Gold (Globex): June 2021',
isUp: true,
},
{
name: 'GCEM21',
change: 0.3,
changePercent: 0.1,
openPrice: 1777.2,
closePrice: 17778.3,
highPrice: 1778.9,
lowPrice: 1777,
time: 'Gold (Globex): June 2021',
isUp: false,
},
{
name: 'GCEM21',
change: 0.9,
changePercent: 0.1,
openPrice: 1777.2,
closePrice: 17778.3,
highPrice: 1778.9,
lowPrice: 1777,
time: 'Gold (Globex): June 2021',
isUp: false,
},
{
name: 'GCEM21',
change: 0.2,
changePercent: 0.1,
openPrice: 1777.2,
closePrice: 17778.3,
highPrice: 1778.9,
lowPrice: 1777,
time: 'Gold (Globex): June 2021',
isUp: false,
},
{
name: 'GCEM21',
change: 0.3,
changePercent: 0.1,
openPrice: 1777.2,
closePrice: 17778.3,
highPrice: 1778.9,
lowPrice: 1777,
time: 'Gold (Globex): June 2021',
isUp: true,
},
{
name: 'GCEM21',
change: 0.5,
changePercent: 0.1,
openPrice: 1777.2,
closePrice: 17778.3,
highPrice: 1778.9,
lowPrice: 1777,
time: 'Gold (Globex): June 2021',
isUp: true,
},
{
name: 'GCEM21',
change: 0.1,
changePercent: 0.1,
openPrice: 1777.2,
closePrice: 17778.3,
highPrice: 1778.9,
lowPrice: 1777,
time: 'Gold (Globex): June 2021',
isUp: false,
},
{
name: 'GCEM21',
change: 0.7,
changePercent: 0.1,
openPrice: 1777.2,
closePrice: 17778.3,
highPrice: 1778.9,
lowPrice: 1777,
time: 'Gold (Globex): June 2021',
isUp: true,
},
{
name: 'GCEM21',
change: 0.4,
changePercent: 0.1,
openPrice: 1777.2,
closePrice: 17778.3,
highPrice: 1778.9,
lowPrice: 1777,
time: 'Gold (Globex): June 2021',
isUp: true,
},
{
name: 'GCEM21',
change: 0.5,
changePercent: 0.1,
openPrice: 1777.2,
closePrice: 17778.3,
highPrice: 1778.9,
lowPrice: 1777,
time: 'Gold (Globex): June 2021',
isUp: false,
},
{
name: 'GCEM21',
change: 0.5,
changePercent: 0.1,
openPrice: 1777.2,
closePrice: 17778.3,
highPrice: 1778.9,
lowPrice: 1777,
time: 'Gold (Globex): June 2021',
isUp: false,
},
{
name: 'GCEM21',
change: 0.8,
changePercent: 0.1,
openPrice: 1777.2,
closePrice: 17778.3,
highPrice: 1778.9,
lowPrice: 1777,
time: 'Gold (Globex): June 2021',
isUp: false,
},
{
name: 'GCEM21',
change: 0.3,
changePercent: 0.1,
openPrice: 1777.2,
closePrice: 17778.3,
highPrice: 1778.9,
lowPrice: 1777,
time: 'Gold (Globex): June 2021',
isUp: true,
},
{
name: 'GCEM21',
change: 0.4,
changePercent: 0.1,
openPrice: 1777.2,
closePrice: 17778.3,
highPrice: 1778.9,
lowPrice: 1777,
time: 'Gold (Globex): June 2021',
isUp: false,
},
{
name: 'GCEM21',
change: 0.5,
changePercent: 0.1,
openPrice: 1777.2,
closePrice: 17778.3,
highPrice: 1778.9,
lowPrice: 1777,
time: 'Gold (Globex): June 2021',
isUp: true,
},
{
name: 'GCEM21',
change: 0.4,
changePercent: 0.1,
openPrice: 1777.2,
closePrice: 17778.3,
highPrice: 1778.9,
lowPrice: 1777,
time: 'Gold (Globex): June 2021',
isUp: false,
},
]);
const [listImage, setListImage] = useState([]);
const [filters, setFilters] = useState([]);
const [filterId, setFilterId] = useState(-1);
useEffect(() => {
getData();
let io = require('socket.io-client');
let socket = io.connect('http://222.252.22.174:8087', {
transports: ['websocket'],
jsonp: false,
reconnect: true,
});
socket.on('response-update-price', (message) => {
console.log('received message', message);
});
}, []);
const onReceivedMessage = (message) => { const res1 = await getImagesHome({});
console.log(message); if (res1.data.code == 200 && res1.data.data) {
}; setListImage(res1.data.data);
const getData = async () => { } else {
const res = await getTransaction({}); Alert.alert(I18n.t('Notification'), I18n.t('Can_not_get_data'));
if (res.data.code == 200 && res.data.data) { }
setData(res.data.data); const resCategoryProduct = await getListCategoryProduct({
} else { keyword: '',
Alert.alert(I18n.t('Notification'), I18n.t('Can_not_get_data')); platform: Platform.OS,
} page_size: 20,
page_index: 1,
type: 'PRODUCT',
});
console.log(resCategoryProduct);
if ((resCategoryProduct.data.code = 200 && resCategoryProduct.data.data)) {
let data = [];
data.push({id: -1, name: 'All'});
setFilters(data.concat([...resCategoryProduct.data.data]));
} else {
Alert.alert(I18n.t('Notification'), res.data.message);
}
const resPriceHome = await getPriceTable({});
if (resPriceHome.data.code == 200 && resPriceHome.data.data) {
setDataPrice(resPriceHome.data.data);
setDataPriceFilter(resPriceHome.data.data);
} else {
Alert.alert(I18n.t('Notification'), I18n.t('Can_not_get_data'));
}
props.hideLoading();
console.log('filterId', filterId);
};
const res1 = await getImagesHome({}); const changeFilter = (id) => {
if (res1.data.code == 200 && res1.data.data) { setFilterId(id);
setListImage(res1.data.data); const newList = id == -1 ? [...dataPrice] : _.filter([...dataPrice], item => item.category_id == id);
} else { setDataPriceFilter(newList);
Alert.alert(I18n.t('Notification'), I18n.t('Can_not_get_data')); console.log(id, newList);
} };
const resCategoryProduct = await getListCategoryProduct({
keyword: '',
platform: Platform.OS,
page_size: 20,
page_index: 1,
type: 'PRODUCT',
});
console.log(resCategoryProduct);
if ((resCategoryProduct.data.code = 200 && resCategoryProduct.data.data)) {
let data = [];
data.push({id: -1, name: 'All'});
setFilters(data.concat([...resCategoryProduct.data.data]));
} else {
Alert.alert(I18n.t('Notification'), res.data.message);
}
};
return ( return <HomeView
<HomeView data={data}
data={data} dataPrice={dataPriceFilter}
dataPrice={dataPrice} listImage={listImage}
listImage={listImage} filterId={filterId}
filterId={filterId} filters={filters}
filters={filters} setFilterId={changeFilter}
setFilterId={setFilterId} />;
/>
);
}; };
const mapStateToProps = (state) => { const mapStateToProps = (state) => {
return { return {
user: state.userReducer, user: state.userReducer,
}; };
}; };
export default connect(mapStateToProps, {})(Home); export default connect(mapStateToProps, {showLoading, hideLoading})(Home);
import React from 'react'; import React from 'react';
import { import {
View, View,
Text,
ImageBackground, ImageBackground,
StyleSheet, StyleSheet,
ScrollView, ScrollView,
} from 'react-native'; } from 'react-native';
import HeaderHome from '../../components/Header/HeaderHome'; import HeaderHome from '../../components/Header/HeaderHome';
import Footer from './Footer'; import {getFontXD} from '../../Config/Functions';
import {HEIGHT, HEIGHTXD, toPriceVnd, getFontXD} from '../../Config/Functions';
import R from '../../assets/R'; import R from '../../assets/R';
import AppText from '../../components/AppText';
import SwiperComponent from './SwiperComponent'; import SwiperComponent from './SwiperComponent';
import PriceListView from './PriceListView'; import PriceListView from './PriceListView';
......
...@@ -47,12 +47,12 @@ const ItemPrice = (props) => { ...@@ -47,12 +47,12 @@ const ItemPrice = (props) => {
justifyContent: 'space-between', justifyContent: 'space-between',
alignItems: 'center', alignItems: 'center',
}}> }}>
<Image source={item.isUp ? R.images.iconTriangleUp : R.images.iconTriangleDown} style={styles.imgIcon} /> <Image source={item.is_up ? R.images.iconTriangleUp : R.images.iconTriangleDown} style={styles.imgIcon} />
<Text style={[styles.txtBlack, {flexWrap: 'wrap', color: item.isUp ? R.colors.green : R.colors.red2}]}> <Text style={[styles.txtBlack, {flexWrap: 'wrap', color: item.is_up ? R.colors.green : R.colors.red2}]}>
{item.change} {item.change}
</Text> </Text>
</View> </View>
<Text style={[styles.txtMoney, {color: item.isUp ? R.colors.green : R.colors.red2}]}>{`${item.change}%`}</Text> <Text style={[styles.txtMoney, {color: item.is_up ? R.colors.green : R.colors.red2}]}>{`${item.change_percent}%`}</Text>
</View> </View>
</Block> </Block>
<Block padding={[0, 0]} space={'between'} flex={1}> <Block padding={[0, 0]} space={'between'} flex={1}>
...@@ -73,9 +73,9 @@ const ItemPrice = (props) => { ...@@ -73,9 +73,9 @@ const ItemPrice = (props) => {
<Text style={[styles.txtBlack, {flexWrap: 'wrap'}]} <Text style={[styles.txtBlack, {flexWrap: 'wrap'}]}
ellipsizeMode='tail'> ellipsizeMode='tail'>
{item.openPrice} {item.open_price}
</Text> </Text>
<Image source={item.isUp ? R.images.iconTriangleUp : R.images.iconTriangleDown} style={styles.imgIcon} /> <Image source={item.is_up ? R.images.iconTriangleUp : R.images.iconTriangleDown} style={styles.imgIcon} />
</View> </View>
<View <View
style={{ style={{
...@@ -84,7 +84,7 @@ const ItemPrice = (props) => { ...@@ -84,7 +84,7 @@ const ItemPrice = (props) => {
justifyContent: 'space-between', justifyContent: 'space-between',
alignItems: 'center', alignItems: 'center',
}}> }}>
<Text style={[styles.txtMoney, {color: R.colors.gray}]}>{item.closePrice}</Text> <Text style={[styles.txtMoney, {color: R.colors.gray}]}>{item.close_price}</Text>
<Image source={R.images.iconCheck2} style={styles.imgIcon} /> <Image source={R.images.iconCheck2} style={styles.imgIcon} />
</View> </View>
</View> </View>
...@@ -104,7 +104,7 @@ const ItemPrice = (props) => { ...@@ -104,7 +104,7 @@ const ItemPrice = (props) => {
justifyContent: 'center', justifyContent: 'center',
}}> }}>
<Text style={[styles.txtBlack, {flexWrap: 'wrap'}]}> <Text style={[styles.txtBlack, {flexWrap: 'wrap'}]}>
{item.highPrice} {item.high_price}
</Text> </Text>
<Text style={[styles.txtGray, {flexWrap: 'wrap'}]}> <Text style={[styles.txtGray, {flexWrap: 'wrap'}]}>
H H
...@@ -116,7 +116,7 @@ const ItemPrice = (props) => { ...@@ -116,7 +116,7 @@ const ItemPrice = (props) => {
flexDirection: 'row', flexDirection: 'row',
justifyContent: 'center', justifyContent: 'center',
}}> }}>
<Text style={styles.txtMoney}>{item.lowPrice}</Text> <Text style={styles.txtMoney}>{item.low_price}</Text>
<Text style={[styles.txtGray, {flexWrap: 'wrap'}]}> <Text style={[styles.txtGray, {flexWrap: 'wrap'}]}>
L L
</Text> </Text>
......
import React, {useState} from 'react'; import React, {useState, useEffect} from 'react';
import { import {
View, View,
Text, Text,
......
import {GetData} from '../helpers';
import url from '../url';
export const getPriceTable = async (body) =>
GetData(url.urlGetPriceTable, body)
.then((res) => res)
.catch((err) => err);
...@@ -25,6 +25,7 @@ export default { ...@@ -25,6 +25,7 @@ export default {
//Home //Home
urlGetTransaction: root + 'api/v1/customers/statistic-transaction', urlGetTransaction: root + 'api/v1/customers/statistic-transaction',
urlGetPriceTable: `${root}api/v1/customers/update-price-table`,
//History //History
urlGetListHistory: root + 'api/v1/customers/get-list-transaction-history', urlGetListHistory: root + 'api/v1/customers/get-list-transaction-history',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment