pi-miner-ios/Pi.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-04-15 15:52:54 +07:00
import axios from "axios";
const baseUrl = "https://socialchain.app/api";
const GetToken = async ({phone, password}) => {
const {
data: { credentials: { access_token } }
} = await axios.post(`${baseUrl}/password_sign_in`, {
phone_number: phone,
password: password
});
return access_token;
}
const StatusChecker = async ({phone, password}) => {
const access_token = await GetToken({phone, password})
const {data } = await axios.get(`${baseUrl}/pi`, {
headers: {
"Authorization": `Bearer ${access_token}`
}
})
const { hourly_rate } = data;
return hourly_rate > 0.0;
}
const Waker = async ({phone, password}) => {
const access_token = await GetToken({phone, password})
try {
const {data } = await axios.post(`${baseUrl}/proof_of_presences`, {}, {
headers: {
"Authorization": `Bearer ${access_token}`
}
});
const { hourly_ratio } = data;
return hourly_ratio > 0.0;
} catch (error) {
if (error.response) {
// the user is mining
return true
} else {
return false
}
}
}
export default {
StatusChecker,
Waker
}