steemconnect login

This commit is contained in:
Hüseyin Terkir 2018-09-11 15:39:52 +03:00
parent a631c13d7e
commit 4a96187049
8 changed files with 282 additions and 152 deletions

29
package-lock.json generated
View File

@ -2455,7 +2455,7 @@
},
"buffer": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-3.6.0.tgz",
"resolved": "http://registry.npmjs.org/buffer/-/buffer-3.6.0.tgz",
"integrity": "sha1-pyyTb3e5a/UvX357RnGAYoVR3vs=",
"requires": {
"base64-js": "0.0.8",
@ -3021,6 +3021,22 @@
"gud": "^1.0.0"
}
},
"cross-fetch": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-1.1.1.tgz",
"integrity": "sha512-+VJE04+UfxxmBfcnmAu/lKor53RUCx/1ilOti4p+JgrnLQ4AZZIRoe2OEd76VaHyWQmQxqKnV+TaqjHC4r0HWw==",
"requires": {
"node-fetch": "1.7.3",
"whatwg-fetch": "2.0.3"
},
"dependencies": {
"whatwg-fetch": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.3.tgz",
"integrity": "sha1-nITsLc9oGH/wC8ZOEnS0QhduHIQ="
}
}
},
"cross-spawn": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz",
@ -9915,6 +9931,15 @@
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
},
"sc2-sdk": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/sc2-sdk/-/sc2-sdk-1.0.2.tgz",
"integrity": "sha512-QADFzQYCsm6OOQE3cxd/NEhSTEtcohzJ6KQN4E5YaEO/bl2WgWy1Dgz4SFRhjIwTh5luzad2TqfUN7uF4IL8xg==",
"requires": {
"cross-fetch": "^1.1.1",
"debug": "^2.2.0"
}
},
"secp256k1": {
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-3.5.0.tgz",
@ -9940,7 +9965,7 @@
"dependencies": {
"commander": {
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.8.1.tgz",
"resolved": "http://registry.npmjs.org/commander/-/commander-2.8.1.tgz",
"integrity": "sha1-Br42f+v9oMMwqh4qBy09yXYkJdQ=",
"requires": {
"graceful-readlink": ">= 1.0.0"

View File

@ -42,7 +42,8 @@
"redux-promise": "^0.6.0",
"redux-thunk": "^2.3.0",
"remarkable": "^1.7.1",
"rn-placeholder": "^1.2.0"
"rn-placeholder": "^1.2.0",
"sc2-sdk": "^1.0.2"
},
"devDependencies": {
"babel-eslint": "^8.2.6",

View File

@ -1,8 +1,11 @@
/*eslint-disable no-unused-vars*/
/*eslint-disable no-console*/
import * as dsteem from "dsteem";
import { getAccount } from "./dsteem";
import { setUserData, setAuthStatus } from "../../realm/realm";
/*eslint-disable-next-line no-unused-vars*/
import { encryptKey, decryptKey } from "../../utils/crypto";
import * as sc2 from "sc2-sdk";
import steemConnect from "./steemConnectAPI";
/*eslint-enable no-unused-vars*/
export const Login = (username, password) => {
let account;
@ -168,3 +171,11 @@ export const Login = (username, password) => {
});
});
};
export const loginWithSC2 = async (access_token) => {
await steemConnect.setAccessToken(access_token);
steemConnect.me((error, result) => {
console.log(error, result);
return result;
});
};

View File

@ -9,7 +9,7 @@ import { parsePosts, parseComments } from "../../utils/postParser";
let rewardFund = null;
let medianPrice = null;
let client;
let client = new Client("https://api.steemit.com");
getClient = async () => {
let server = await AsyncStorage.getItem("server");

View File

@ -0,0 +1,8 @@
import sc2 from "sc2-sdk";
const api = sc2.Initialize({
app: "esteem-app",
callbackURL: "http://localhost:3415",
});
export default api;

View File

@ -14,6 +14,7 @@ import Editor from "./editor/editor";
import Discover from "./discover/discover";
import Settings from "./settings/settings";
import Notifications from "./notifications/notification";
import SteemConnect from "./steem-connect/steemConnect";
import PostCard from "../components/post-card/postCard";
import Search from "../components/search/search";
@ -40,6 +41,7 @@ function registerScreens() {
Navigation.registerComponent("navigation.eSteem.Author", () => Author);
Navigation.registerComponent("navigation.eSteem.PostCard", () => PostCard);
Navigation.registerComponent("navigation.eSteem.Search", () => Search);
Navigation.registerComponent("navigation.eSteem.SteemConnect", () => SteemConnect);
}
module.exports = {

View File

@ -9,7 +9,8 @@ import {
Linking,
BackHandler,
Dimensions,
TextInput
TextInput,
WebView
} from "react-native";
import Ionicons from "react-native-vector-icons/Ionicons";
@ -75,6 +76,9 @@ class LoginPage extends Component {
Navigation.pop(this.props.componentId);
return true;
});
Linking.getInitialURL().then((url) => {
console.log(url);
});
}
componentWillUnmount() {
@ -112,6 +116,26 @@ class LoginPage extends Component {
}
}
loginwithSc2 = () => {
Navigation.showModal({
stack: {
children: [{
component: {
name: "navigation.eSteem.SteemConnect",
passProps: {},
options: {
topBar: {
title: {
text: "Login via SC2"
}
}
}
}
}]
}
});
}
render() {
return (
<View style={{ flex: 1 }}>
@ -315,7 +339,37 @@ class LoginPage extends Component {
</View>
<View tabLabel="SteemConnect" style={styles.tabbarItem}>
<TouchableOpacity
onPress={this.loginwithSc2}
style={{
flex: 0.4,
width: 100,
height: 50,
borderRadius: 30,
backgroundColor: '#357ce6',
flexDirection: 'row',
}}>
<View style={{ flex: 1, flexDirection: 'row' }}>
<Ionicons
color='white'
name='md-person'
style={{
alignSelf: 'center',
fontSize: 25,
flex: 0.4,
left: 15
}}/>
<Text style={{
color: 'white',
fontWeight: '600',
alignSelf: 'center',
fontSize: 16,
flex: 0.6,
}}>
LOGIN
</Text>
</View>
</TouchableOpacity>
</View>
</ScrollableTabView>
</View>

View File

@ -0,0 +1,29 @@
import React, { Component } from "react";
import { View, Text, WebView } from "react-native";
import { loginWithSC2 } from "../../providers/steem/auth";
export default class SteemConnect extends Component {
constructor(props) {
super(props);
this.state = {
};
}
onNavigationStateChange(event){
console.log(event.url);
let access_token = event.url.match(/\?(?:access_token)\=([\S\s]*?)\&/)[1];
console.log(access_token);
loginWithSC2(access_token);
}
render() {
return (
<View style={{ flex: 1 }}>
<WebView
onNavigationStateChange={state => this.onNavigationStateChange(state)}
// TODO: Move it to constants as a object
source={{ uri: "https://steemconnect.com/oauth2/authorize?client_id=esteem-app&redirect_uri=http%3A%2F%2F127.0.0.1%3A3415%2F&scope=vote%2Ccomment%2Cdelete_comment%2Ccomment_options%2Ccustom_json%2Cclaim_reward_balance" }}/>
</View>
);
}
}