Skip to content

Instantly share code, notes, and snippets.

View linux08's full-sized avatar
📚
Learning.

David Abimbola linux08

📚
Learning.
View GitHub Profile
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 () => {
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 />
import React from 'react';
import {
ActivityIndicator,
AsyncStorage,
StatusBar,
StyleSheet,
View,
} from 'react-native';
import { MyContext } from '../Provider';
import React from 'react';
import {
AsyncStorage,
Button,
StatusBar,
StyleSheet,
View,
Text,
} from 'react-native';
import { MyContext } from '../Provider';
//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) => {
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;
componentDidMount() {
const config = {
method: 'GET',
headers: {
Accept: 'application/json'
},
};
fetch('http://10.0.2.2:5000/images', config)
.then((resp) => resp.json())
.then((res) => {
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);
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);
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);