Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
riverrun46 committed Mar 5, 2024
2 parents 04b9f2a + f101a5d commit e75484b
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"decimal.js": "^10.4.3",
"ecpair": "^2.1.0",
"memfs": "^4.5.0",
"meta-contract": "^0.4.0",
"meta-contract": "^0.4.2",
"mvc-std-lib": "^1.1.4",
"object-hash": "^3.0.0",
"qrcode": "^1.5.3",
Expand Down
11 changes: 11 additions & 0 deletions src/pages/settings/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ const toConnectedDapps = () => {
router.push('/connected-dapps')
}
const toToolkit = () => {
router.push('/settings/toolkit')
}
const showResetModal = ref(false)
</script>

Expand Down Expand Up @@ -86,6 +90,13 @@ const showResetModal = ref(false)
</div>
</div>

<div class="setting-item group cursor-pointer" @click="toToolkit">
<div class="text-gray-500 group-hover:underline">Toolkit</div>
<div class="">
<ChevronRightIcon class="link-icon" />
</div>
</div>

<div class="setting-item group cursor-pointer" @click="openWindowMode" v-if="!IS_DEV">
<div class="text-gray-500 group-hover:underline">Open in Window Mode</div>
<div class="">
Expand Down
43 changes: 43 additions & 0 deletions src/pages/settings/Toolkit.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<script lang="ts" setup>
import { useRouter } from 'vue-router'
import { ChevronRightIcon } from '@heroicons/vue/20/solid'
const router = useRouter()
const toSpaceMerge = () => {
router.push('/settings/toolkit/space-merge')
}
</script>

<template>
<div class="space-y-8 pt-4 text-sm">
<!-- security -->
<div class="space-y-2">
<div class="divide-y divide-gray-100">
<div class="setting-item group cursor-pointer" @click="toSpaceMerge">
<div class="text-gray-500 group-hover:underline">Space Merge</div>
<div class="">
<ChevronRightIcon class="link-icon" />
</div>
</div>

<div class="setting-item group cursor-not-allowed" title="coming sonn">
<div class="text-gray-500 group-hover:underline">Ft Merge</div>
<div class="">
<ChevronRightIcon class="link-icon" />
</div>
</div>
</div>
</div>
</div>
</template>

<style lang="css" scoped>
.setting-item {
@apply -mx-2 flex items-center justify-between px-2 py-4 transition-all duration-200 ease-in-out hover:bg-gray-300/20;
}
.link-icon {
@apply h-4 w-4 text-gray-500 group-hover:text-blue-500;
}
</style>
86 changes: 86 additions & 0 deletions src/pages/settings/components/SpaceMerge.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<script setup lang="ts">
import { computed, ref } from 'vue'
import { FEEB } from '@/data/config'
import { getApiHost } from '@/lib/host'
import { getNetwork } from '@/lib/network'
import { getPrivateKey, getAddress } from '@/lib/account'
import { API_NET, API_TARGET, Wallet } from 'meta-contract'
import { useMVCUTXOQuery } from '@/queries/utxos'
import { fetchSpaceBalance } from '@/queries/balance'
import TransactionResultModal, { type TransactionResult } from '@/pages/wallet/components/TransactionResultModal.vue'
const address = ref()
const isOpenResultModal = ref(false)
const transactionResult = ref<TransactionResult | undefined>()
const merge = async () => {
const network: API_NET = (await getNetwork()) as API_NET
const purse = await getPrivateKey('mvc')
const apiHost = await getApiHost()
const wallet = new Wallet(purse, network, FEEB, API_TARGET.MVC, apiHost)
let { txId } = await wallet.merge().catch((err) => {
isOpenResultModal.value = true
transactionResult.value = {
status: 'warning',
message: err.message,
}
throw err
})
isOpenResultModal.value = true
const balance = await fetchSpaceBalance(address.value)
transactionResult.value = {
chain: 'mvc',
status: 'success',
txId,
fromAddress: address.value,
toAdddress: address.value,
amount: balance.total,
token: {
symbol: 'SPACE',
decimal: 8,
},
}
}
getAddress('mvc').then((_address) => {
address.value = _address
})
const { data } = useMVCUTXOQuery(address, { enabled: computed(() => !!address.value) })
</script>

<template>
<div class="space-y-4">
<div class="space-y-2">
<div class="label">MVC Address</div>
<div class="value">{{ address }}</div>
</div>

<div class="space-y-2">
<div class="label">UTXO Count</div>
<div class="value">{{ data?.length ? (data.length >= 300 ? '>=300' : data.length) : '--' }}</div>
</div>

<button
@click="merge"
:disabled="!data || data.length < 3"
:class="[
'bg-primary-blue text-white py-2 rounded-md text-xs w-full',
!data || data.length < 3 ? 'cursor-not-allowed opacity-50' : null,
]"
>
Merge
</button>
<TransactionResultModal v-model:is-open-result="isOpenResultModal" :result="transactionResult" />
</div>
</template>

<style lang="css" scoped>
.label {
@apply text-sm font-bold text-gray-500;
}
.value {
@apply text-sm text-gray-700;
}
</style>
6 changes: 3 additions & 3 deletions src/pages/wallet/components/AssetItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ watch(
<div v-if="asset?.contract === 'BRC-20'" class="w-full mt-2.5 space-y-2">
<div class="text-xs flex items-center justify-between w-full">
<span class="text-[#909399]">Transferable:</span>
<span class="text-black-primary font-bold truncate">{{ asset.balance?.transferBalance || '--' }}</span>
<span class="text-black-primary font-bold truncate">{{ asset.balance?.transferBalance }}</span>
</div>
<div class="text-xs flex items-center justify-between w-full">
<span class="text-[#909399]">Available:</span>
<span class="text-black-primary font-bold truncate">{{ asset.balance?.availableBalanceSafe || '--' }}</span>
<span class="text-black-primary font-bold truncate">{{ asset.balance?.availableBalanceSafe }}</span>
</div>
<div class="text-xs flex items-center justify-between w-full" v-if="asset.balance?.availableBalanceUnSafe">
<span class="text-[#909399]">Available(pending):</span>
<span class="text-black-primary font-bold truncate">{{ asset.balance?.availableBalanceUnSafe || '--' }}</span>
<span class="text-black-primary font-bold truncate">{{ asset.balance?.availableBalanceUnSafe }}</span>
</div>
</div>
</div>
Expand Down
12 changes: 11 additions & 1 deletion src/queries/utxos.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Chain } from '@/lib/account'
import { getNet } from '@/lib/network'
import { Ref, ComputedRef } from 'vue'
import { useQuery } from '@tanstack/vue-query'
import { mvcApi, mempoolApi, metaletApiV3 } from './request'

export interface UTXO {
Expand Down Expand Up @@ -40,7 +42,7 @@ export type Utxo = {

export const fetchUtxos = async (chain: Chain = 'mvc', address: string): Promise<any[]> => {
if (chain === 'mvc') {
return await fetchMVCUtxos(address)
return (await fetchMVCUtxos(address)) || []
} else {
return (await getBtcUtxos(address)) || []
}
Expand Down Expand Up @@ -116,3 +118,11 @@ export async function getUtxos(address: string): Promise<UTXO[]> {
const utxos = await mempoolApi<MempoolUtxo[]>(`/address/${address}/utxo`).get()
return utxos.map((utxo) => formatMempoolUTXO(utxo))
}

export const useMVCUTXOQuery = (address: Ref<string>, options: { enabled: ComputedRef<boolean> }) => {
return useQuery({
queryKey: ['MVCUTXOs', { address }],
queryFn: () => fetchMVCUtxos(address.value),
...options,
})
}
18 changes: 18 additions & 0 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,24 @@ const routes = [
noFooter: true,
},
},
{
path: '/settings/toolkit',
component: () => import('./pages/settings/Toolkit.vue'),
meta: {
secondaryHeader: true,
headerTitle: 'Toolkit',
noFooter: false,
},
},
{
path: '/settings/toolkit/space-merge',
component: () => import('./pages/settings/components/SpaceMerge.vue'),
meta: {
secondaryHeader: true,
headerTitle: 'Space Merge',
noFooter: false,
},
},

{
path: '/tools/path-finder',
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2995,10 +2995,10 @@ merge2@^1.3.0:
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae"
integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==

meta-contract@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/meta-contract/-/meta-contract-0.4.0.tgz#e2e28129874bb51bde6534dbb7ccf0afb4eb853b"
integrity sha512-bzRCiZEcs/exaMHMz86aYM5xNHO4b8f8BkNFGzAZYzQIEPg2dkb8w9tgfXytHKboBh4Lf4wqcMyIZHcIHDAxEw==
meta-contract@^0.4.2:
version "0.4.2"
resolved "https://registry.yarnpkg.com/meta-contract/-/meta-contract-0.4.2.tgz#3f74fe1aaaa351a3b3c92746cd6af961a1e2fbb9"
integrity sha512-0aEoE8K5iUAQdCCqxjWoanIJJUnjSWjeCZ9lnKhviorU2Cq2cE/QHNCn3+yyxPrhsKPcFfJ84CXECveg0dpoMA==
dependencies:
mvc-scrypt "0.1.2"
node-fetch "2"
Expand Down

0 comments on commit e75484b

Please sign in to comment.