-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const axios = require('axios'); | ||
|
||
const PI_API_BASE_URL = 'https://api.minepi.com'; // Replace with actual Pi Network API URL | ||
|
||
// Function to authenticate user | ||
async function authenticateUser (username, password) { | ||
try { | ||
const response = await axios.post(`${PI_API_BASE_URL}/auth/login`, { | ||
username, | ||
password, | ||
}); | ||
return response.data; | ||
} catch (error) { | ||
console.error('Error authenticating user:', error); | ||
throw new Error('Authentication failed'); | ||
} | ||
} | ||
|
||
// Function to get user balance | ||
async function getUser Balance(userId, token) { | ||
try { | ||
const response = await axios.get(`${PI_API_BASE_URL}/users/${userId}/balance`, { | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}); | ||
return response.data.balance; | ||
} catch (error) { | ||
console.error('Error fetching user balance:', error); | ||
throw new Error('Unable to fetch user balance'); | ||
} | ||
} | ||
|
||
// Function to get user transaction history | ||
async function getUser TransactionHistory(userId, token) { | ||
try { | ||
const response = await axios.get(`${PI_API_BASE_URL}/users/${userId}/transactions`, { | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}); | ||
return response.data.transactions; | ||
} catch (error) { | ||
console.error('Error fetching user transaction history:', error); | ||
throw new Error('Unable to fetch transaction history'); | ||
} | ||
} | ||
|
||
module.exports = { authenticateUser , getUser Balance, getUser TransactionHistory }; |