Skip to content

Commit

Permalink
chore: update mvc utxo api
Browse files Browse the repository at this point in the history
  • Loading branch information
AricRedemption committed Sep 6, 2024
1 parent cca3e49 commit 494f56d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/queries/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ export const metaletApiV3 = <T>(path: string) => {
}
}

export const metaletApiV4 = <T>(path: string) => {
const metaletHost = METALET_HOST + '/wallet-api/v4'
return {
get: (params?: OptionParams) =>
metaletV3Request<T>(`${metaletHost}${path}`, { method: 'GET', params, withCredential: true }),
post: (data?: OptionData) =>
metaletV3Request<T>(`${metaletHost}${path}`, { method: 'POST', data, withCredential: true }),
}
}

export const ordinalsApi = (path: string) => {
const url = path.includes(ORDINALS_HOST) ? path : `${ORDINALS_HOST}${path}`
return {
Expand Down
16 changes: 12 additions & 4 deletions src/queries/utxos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { Chain } from '@/lib/types'
import { MRC20UTXO } from './mrc20'
import { getNet } from '@/lib/network'
import { Ref, ComputedRef } from 'vue'
import { getSafeUtxos } from '@/lib/utxo'
import { useQuery } from '@tanstack/vue-query'
import { UNISAT_ENABLED } from '@/data/config'
import { fetchBtcTxHex } from '@/queries/transaction'
import { mvcApi, mempoolApi, metaletApiV3, unisatApi } from './request'
import { mvcApi, mempoolApi, metaletApiV3, unisatApi, metaletApiV4 } from './request'

export interface UTXO {
txId: string
Expand All @@ -31,8 +30,17 @@ export type MvcUtxo = {
height: number
}

const fetchMVCUtxos = async (address: string): Promise<MvcUtxo[]> => {
return (await mvcApi<MvcUtxo[]>(`/address/${address}/utxo`)).get()
const fetchMVCUtxos = async (address: string, useUnconfirmed = true): Promise<MvcUtxo[]> => {
const net = getNet()
let { list = [] } = await metaletApiV4<{ list: MvcUtxo[] }>('/mvc/address/utxo-list').get({
address,
net,
})
list = list.filter((utxo) => utxo.value >= 600)
if (!useUnconfirmed) {
list = list.filter((utxo) => utxo.height > 0)
}
return list
}

export type Utxo = {
Expand Down

0 comments on commit 494f56d

Please sign in to comment.