mirror of
https://github.com/pezkuwichain/pezkuwi-mobile-app.git
synced 2026-07-23 17:25:42 +00:00
auto-commit for 7352dbe7-159b-4c84-b388-5470d6435ad4
This commit is contained in:
@@ -1,13 +1,15 @@
|
|||||||
// PezkuwiChain API Service
|
// PezkuwiChain API Service
|
||||||
// Connects to DKSweb backend running on localhost:8080
|
// Connects to our FastAPI backend (proxy to blockchain)
|
||||||
|
|
||||||
const API_BASE_URL = 'http://localhost:8080';
|
import Constants from 'expo-constants';
|
||||||
|
|
||||||
|
const BACKEND_URL = Constants.expoConfig?.extra?.EXPO_PUBLIC_BACKEND_URL || 'http://localhost:8001';
|
||||||
|
const API_BASE = `${BACKEND_URL}/api`;
|
||||||
|
|
||||||
interface WalletBalance {
|
interface WalletBalance {
|
||||||
address: string;
|
address: string;
|
||||||
hez: string;
|
hez: string;
|
||||||
pez: string;
|
pez: string;
|
||||||
usdt: string;
|
|
||||||
transferrable: string;
|
transferrable: string;
|
||||||
reserved: string;
|
reserved: string;
|
||||||
}
|
}
|
||||||
@@ -18,24 +20,33 @@ interface Transaction {
|
|||||||
to: string;
|
to: string;
|
||||||
amount: string;
|
amount: string;
|
||||||
asset: string;
|
asset: string;
|
||||||
timestamp: number;
|
timestamp: string;
|
||||||
status: string;
|
status: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
class PezkuwiAPI {
|
class PezkuwiAPI {
|
||||||
private baseUrl: string;
|
private baseUrl: string;
|
||||||
|
|
||||||
constructor(baseUrl: string = API_BASE_URL) {
|
constructor() {
|
||||||
this.baseUrl = baseUrl;
|
this.baseUrl = API_BASE;
|
||||||
|
console.log('✅ PezkuwiAPI initialized:', this.baseUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get wallet balance
|
// Get wallet balance
|
||||||
async getBalance(address: string): Promise<WalletBalance> {
|
async getBalance(address: string): Promise<WalletBalance> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${this.baseUrl}/api/wallet/${address}/balance`);
|
const response = await fetch(`${this.baseUrl}/blockchain/balance`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ address }),
|
||||||
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to fetch balance');
|
throw new Error('Failed to fetch balance');
|
||||||
}
|
}
|
||||||
|
|
||||||
return await response.json();
|
return await response.json();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching balance:', error);
|
console.error('Error fetching balance:', error);
|
||||||
@@ -44,12 +55,14 @@ class PezkuwiAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get transaction history
|
// Get transaction history
|
||||||
async getTransactions(address: string): Promise<Transaction[]> {
|
async getTransactions(address: string): Promise<{ address: string; transactions: Transaction[] }> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${this.baseUrl}/api/wallet/${address}/transactions`);
|
const response = await fetch(`${this.baseUrl}/blockchain/transactions/${address}`);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to fetch transactions');
|
throw new Error('Failed to fetch transactions');
|
||||||
}
|
}
|
||||||
|
|
||||||
return await response.json();
|
return await response.json();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching transactions:', error);
|
console.error('Error fetching transactions:', error);
|
||||||
@@ -60,10 +73,12 @@ class PezkuwiAPI {
|
|||||||
// Get citizenship status
|
// Get citizenship status
|
||||||
async getCitizenshipStatus(address: string) {
|
async getCitizenshipStatus(address: string) {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${this.baseUrl}/api/citizenship/${address}/status`);
|
const response = await fetch(`${this.baseUrl}/citizenship/status/${address}`);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to fetch citizenship status');
|
throw new Error('Failed to fetch citizenship status');
|
||||||
}
|
}
|
||||||
|
|
||||||
return await response.json();
|
return await response.json();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching citizenship status:', error);
|
console.error('Error fetching citizenship status:', error);
|
||||||
@@ -71,77 +86,21 @@ class PezkuwiAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Submit citizenship application
|
|
||||||
async submitCitizenshipApplication(data: any) {
|
|
||||||
try {
|
|
||||||
const response = await fetch(`${this.baseUrl}/api/citizenship/apply`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify(data),
|
|
||||||
});
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to submit application');
|
|
||||||
}
|
|
||||||
return await response.json();
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error submitting application:', error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get governance proposals
|
// Get governance proposals
|
||||||
async getProposals() {
|
async getProposals() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${this.baseUrl}/api/governance/proposals`);
|
const response = await fetch(`${this.baseUrl}/governance/proposals`);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to fetch proposals');
|
throw new Error('Failed to fetch proposals');
|
||||||
}
|
}
|
||||||
|
|
||||||
return await response.json();
|
return await response.json();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching proposals:', error);
|
console.error('Error fetching proposals:', error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vote on proposal
|
|
||||||
async voteProposal(proposalId: string, vote: 'yes' | 'no', address: string) {
|
|
||||||
try {
|
|
||||||
const response = await fetch(`${this.baseUrl}/api/governance/vote`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
proposalId,
|
|
||||||
vote,
|
|
||||||
address,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to submit vote');
|
|
||||||
}
|
|
||||||
return await response.json();
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error voting:', error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get staking info
|
|
||||||
async getStakingInfo(address: string) {
|
|
||||||
try {
|
|
||||||
const response = await fetch(`${this.baseUrl}/api/staking/${address}`);
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to fetch staking info');
|
|
||||||
}
|
|
||||||
return await response.json();
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching staking info:', error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const pezkuwiAPI = new PezkuwiAPI();
|
export const pezkuwiAPI = new PezkuwiAPI();
|
||||||
|
|||||||
Reference in New Issue
Block a user