Skip to content

Commit 37b73ce

Browse files
committed
fetch coin from api action
1 parent 54d2d4a commit 37b73ce

File tree

7 files changed

+50
-2
lines changed

7 files changed

+50
-2
lines changed

App.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import {StyleSheet, Text, View} from 'react-native';
33
import {Provider} from "react-redux";
44

5-
import {Header} from "./src/components";
5+
import {Header, CryptoContainer} from "./src/components";
66
import Store from "./src/Store";
77

88
export default class App extends React.Component {
@@ -11,6 +11,7 @@ export default class App extends React.Component {
1111
<Provider store={Store}>
1212
<View>
1313
<Header>Crypto Tracker</Header>
14+
<CryptoContainer />
1415
</View>
1516
</Provider>
1617
);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"preset": "jest-expo"
2828
},
2929
"dependencies": {
30+
"axios": "^0.18.0",
3031
"expo": "^25.0.0",
3132
"react": "16.2.0",
3233
"react-native": "0.52.0",

src/Actions/FetchCoinData.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import axios from "axios";
2+
import { apiBaseUrl } from "../Utils/Constants";
3+
import { FETCHING_COIN_DATA, FETCHING_COIN_DATA_SUCCESS, FETCHING_COIN_DATA_FAIL } from "../Utils/ActionTypes";
4+
5+
6+
export default function FetchCoinData() {
7+
return dispatch => {
8+
dispatch({ type: FETCHING_COIN_DATA })
9+
10+
return axios.get(`${apiBaseUrl}/v1/ticker/?limit=10`)
11+
.then(res => {
12+
dispatch({ type: FETCHING_COIN_DATA_SUCCESS, payload: res.data})
13+
})
14+
.catch(err => {
15+
dispatch({ type: FETCHING_COIN_DATA_FAIL, payload: err.data})
16+
})
17+
}
18+
}

src/Utils/ActionTypes.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const FETCHING_COIN_DATA = "FETCHING_COIN_DATA";
2+
export const FETCHING_COIN_DATA_SUCCESS = "FETCHING_COIN_DATA_SUCCESS";
3+
export const FETCHING_COIN_DATA_FAIL = "FETCHING_COIN_DATA_FAIL";

src/Utils/Constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const apiBaseUrl = "https://api.coinmarketcap.com";
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React, { Component } from "react";
2+
import { View, Text } from "react-native";
3+
import { connect } from "react-redux";
4+
5+
6+
class CryptoContainer extends Component {
7+
8+
render() {
9+
return (
10+
<View>
11+
<Text>Nani is this shit</Text>
12+
</View>
13+
)
14+
}
15+
}
16+
17+
function mapStateToProps(state) {
18+
return {
19+
crypto: state.crypto
20+
}
21+
}
22+
23+
export default connect(mapStateToProps)(CryptoContainer);

src/components/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Header from "./Header/Header";
2+
import CryptoContainer from "./CryptoContainer/CryptoContainer"
23

34

4-
export { Header };
5+
export { Header, CryptoContainer };

0 commit comments

Comments
 (0)