Adds equity eligibility check for expenses
Improves the expense tracking component by fetching user information to determine equity eligibility. This allows displaying the "Convert to equity" checkbox only to eligible users, enhancing the user experience and ensuring accurate expense categorization. Also includes error handling to prevent the form from breaking if user information cannot be loaded.
This commit is contained in:
parent
53c14044ef
commit
fff42d170e
3 changed files with 60 additions and 7 deletions
|
|
@ -7,7 +7,8 @@ import type {
|
|||
Account,
|
||||
ExpenseEntryRequest,
|
||||
ExpenseEntry,
|
||||
AccountNode
|
||||
AccountNode,
|
||||
UserInfo
|
||||
} from '../types'
|
||||
import { appConfig } from '@/app.config'
|
||||
|
||||
|
|
@ -263,4 +264,32 @@ export class ExpensesAPI extends BaseService {
|
|||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user information including equity eligibility
|
||||
*
|
||||
* @param walletKey - Wallet key for authentication (invoice key)
|
||||
*/
|
||||
async getUserInfo(walletKey: string): Promise<UserInfo> {
|
||||
try {
|
||||
const response = await fetch(`${this.baseUrl}/castle/api/v1/user/info`, {
|
||||
method: 'GET',
|
||||
headers: this.getHeaders(walletKey),
|
||||
signal: AbortSignal.timeout(this.config?.apiConfig?.timeout || 30000)
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch user info: ${response.statusText}`)
|
||||
}
|
||||
|
||||
return await response.json()
|
||||
} catch (error) {
|
||||
console.error('[ExpensesAPI] Error fetching user info:', error)
|
||||
// Return default non-eligible user on error
|
||||
return {
|
||||
user_id: '',
|
||||
is_equity_eligible: false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue