Refactor wallet balance handling and integrate PaymentService for centralized management
- Replaced direct wallet balance computation in Navbar and WalletPage with a centralized totalBalance property from PaymentService, improving code maintainability. - Updated CreateProductDialog, CreateStoreDialog, and MerchantStore components to utilize PaymentService for retrieving wallet admin and invoice keys, enhancing consistency across the application. - These changes streamline wallet management and improve the overall architecture of the wallet module.
This commit is contained in:
parent
c064b0b40d
commit
e5db949aae
6 changed files with 69 additions and 21 deletions
|
|
@ -269,6 +269,7 @@ const emit = defineEmits<{
|
|||
|
||||
// Services
|
||||
const nostrmarketAPI = injectService(SERVICE_TOKENS.NOSTRMARKET_API) as NostrmarketAPI
|
||||
const paymentService = injectService(SERVICE_TOKENS.PAYMENT_SERVICE) as any
|
||||
const toast = useToast()
|
||||
|
||||
// Local state
|
||||
|
|
@ -342,8 +343,11 @@ const loadAvailableZones = async () => {
|
|||
const currentUser = auth.currentUser?.value
|
||||
if (!currentUser?.wallets?.length) return
|
||||
|
||||
const inkey = paymentService.getPreferredWalletInvoiceKey()
|
||||
if (!inkey) return
|
||||
|
||||
try {
|
||||
const zones = await nostrmarketAPI.getZones(currentUser.wallets[0].inkey)
|
||||
const zones = await nostrmarketAPI.getZones(inkey)
|
||||
availableZones.value = zones
|
||||
|
||||
// Auto-select the first available zone to make form valid
|
||||
|
|
@ -370,9 +374,14 @@ const addNewZone = async () => {
|
|||
return
|
||||
}
|
||||
|
||||
const adminKey = paymentService.getPreferredWalletAdminKey()
|
||||
if (!adminKey) {
|
||||
throw new Error('No wallet admin key available')
|
||||
}
|
||||
|
||||
try {
|
||||
const createdZone = await nostrmarketAPI.createZone(
|
||||
currentUser.wallets[0].adminkey,
|
||||
adminKey,
|
||||
{
|
||||
name: newZone.name!,
|
||||
currency: values.currency!,
|
||||
|
|
@ -418,9 +427,14 @@ const createStore = async (formData: any) => {
|
|||
selectedZones.includes(zone.id)
|
||||
)
|
||||
|
||||
const wallet = paymentService.getPreferredWallet()
|
||||
if (!wallet) {
|
||||
throw new Error('No wallet available')
|
||||
}
|
||||
|
||||
const stallData: CreateStallRequest = {
|
||||
name,
|
||||
wallet: currentUser.wallets[0].id,
|
||||
wallet: wallet.id,
|
||||
currency,
|
||||
shipping_zones: selectedZoneData,
|
||||
config: {
|
||||
|
|
@ -428,8 +442,13 @@ const createStore = async (formData: any) => {
|
|||
}
|
||||
}
|
||||
|
||||
const adminKey = paymentService.getPreferredWalletAdminKey()
|
||||
if (!adminKey) {
|
||||
throw new Error('No wallet admin key available')
|
||||
}
|
||||
|
||||
const newStall = await nostrmarketAPI.createStall(
|
||||
currentUser.wallets[0].adminkey,
|
||||
adminKey,
|
||||
stallData
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue