-
Notifications
You must be signed in to change notification settings - Fork 3
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
25 changed files
with
874 additions
and
373 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Binary file not shown.
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
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
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,46 @@ | ||
import { apiRequest } from '../middleware/middleware'; | ||
import { balanceStore } from '../stores/BalanceStore'; | ||
import { LoginCredentials, LoginResponse, BalanceResponse } from '../types/api.types'; | ||
import { authService } from '../services/auth.service'; | ||
|
||
// Auth endpoints | ||
export const authEndpoints = { | ||
login: async (credentials: LoginCredentials): Promise<LoginResponse> => { | ||
const response = await apiRequest<LoginResponse>({ | ||
url: '/login', | ||
method: 'POST', | ||
data: credentials | ||
}); | ||
|
||
if (!response.token) { | ||
throw new Error('No token received'); | ||
} | ||
|
||
// Store the token | ||
authService.setToken(response.token); | ||
|
||
return response; | ||
} | ||
}; | ||
|
||
// Balance endpoints | ||
export const balanceEndpoints = { | ||
fetchBalance: async (): Promise<BalanceResponse> => { | ||
try { | ||
const response = await apiRequest<BalanceResponse>({ | ||
url: '/balance', | ||
method: 'GET' | ||
}); | ||
|
||
// Update balance store with the response | ||
if (response) { | ||
balanceStore.setBalance(response.balance, response.currency); | ||
} | ||
|
||
return response; | ||
} catch (error) { | ||
console.error('Error fetching balance:', error); | ||
throw error; | ||
} | ||
} | ||
}; |
Oops, something went wrong.