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
import React, { Component } from 'react'; | |
import { AsyncStorage } from 'react-native'; | |
export const MyContext = React.createContext(); | |
export default class MyProvider extends Component { | |
state = { | |
token: '', | |
saveToken: async () => { |
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
import React from 'react'; | |
import { StyleSheet, View, Text } from 'react-native'; | |
import { AppNavigator} from './navigator'; | |
import MyProvider from './Provider'; | |
export default () => ( | |
<MyProvider> | |
<View style={styles.container}> | |
<AppNavigator /> |
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
import React from 'react'; | |
import { | |
ActivityIndicator, | |
AsyncStorage, | |
StatusBar, | |
StyleSheet, | |
View, | |
} from 'react-native'; | |
import { MyContext } from '../Provider'; |
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
import React from 'react'; | |
import { | |
AsyncStorage, | |
Button, | |
StatusBar, | |
StyleSheet, | |
View, | |
Text, | |
} from 'react-native'; | |
import { MyContext } from '../Provider'; |
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
//orders the item in an array of object by their ranking in ascending order | |
function sort(data) { | |
return data.sort((a, b) => { | |
return a.ranking - b.ranking; | |
}); | |
}; | |
//find the average ranking present in an array of object; | |
function average(data) { | |
return ( | |
data.reduce((prev, curr) => { |
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
pragma solidity ^0.4.0; | |
contract SaveAddress { | |
string ipfsHash; | |
function saveHash(string x) public { | |
ipfsHash = x; | |
} | |
function getHash( string y) public view returns ( string x) { | |
return ipfsHash; |
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
componentDidMount() { | |
const config = { | |
method: 'GET', | |
headers: { | |
Accept: 'application/json' | |
}, | |
}; | |
fetch('http://10.0.2.2:5000/images', config) | |
.then((resp) => resp.json()) | |
.then((res) => { |
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
exports.uploadFile = async (req, res, next) => { | |
if (!req.file) { | |
return res.status(422).json({ | |
error: 'File needs to be provided.', | |
}); | |
} | |
const mime = req.file.mimetype; | |
if (mime.split('/')[0] !== 'image') { | |
fs.unlink(req.file.path); |
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
exports.postData = async (req, res, next) => { | |
try { | |
const { hash } = req.data[0]; | |
const accounts = await web3.eth.getAccounts(); | |
const resp = await SavingContract.methods.saveHash(hash) | |
.send({ | |
from: accounts[0], | |
}); | |
const data = Object.assign({ ipfsHash: hash }, resp); |
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
exports.create = async (req, res) => { | |
try { | |
const data = { | |
label: req.body.label, | |
ipfsHash: req.data.ipfsHash, | |
ipfsAddress: `https://gateway.ipfs.io/ipfs/${req.data.ipfsHash}`, | |
transactionHash: req.data.ipfsHash, | |
blockHash: req.data.blockHash, | |
}; | |
const resp = await Image.create(data); |