Skip to content

Commit

Permalink
chore: Updata UI
Browse files Browse the repository at this point in the history
  • Loading branch information
AricRedemption committed Mar 14, 2024
1 parent 41c9fd2 commit 50dbee5
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 24 deletions.
14 changes: 8 additions & 6 deletions src/components/AssetLogo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,31 @@ import BTCNetworkLogo from '@/assets/icons-v3/network_btc.svg'
import MVCNetworkLogo from '@/assets/icons-v3/network_mvc.svg'
import IncomeLogo from '@/assets/icons-v3/income.svg'
import ExpenseLogo from '@/assets/icons-v3/expense.svg'
import FlexBox from './FlexBox.vue'
const { logo, chain, symbol } = defineProps<{
logo?: string
chain?: Chain
symbol: string
type: 'network' | 'activity'
flow?: 'Send' | 'Receive'
}>()
</script>

<template>
<div class="h-15 w-15 relative">
<img v-if="logo" :src="logo" :alt="symbol" class="w-full" />
<div v-else class="leading-15 rounded-full text-center text-white text-3xl bg-blue-primary">
<div class="relative text-3xl">
<img v-if="logo" :src="logo" :alt="symbol" class="w-full aspect-square" />
<FlexBox ai="center" jc="center" v-else class="rounded-full aspect-square text-white bg-blue-primary">
{{ symbol[0].toLocaleUpperCase() }}
</div>
</FlexBox>

<template v-if="type === 'network'">
<BTCNetworkLogo v-if="chain === 'btc'" class="absolute bottom-0 right-0" />
<MVCNetworkLogo v-else-if="chain === 'mvc'" class="absolute bottom-0 right-0" />
</template>
<template v-else-if="type === 'activity'">
<IncomeLogo v-if="chain === 'btc'" class="absolute bottom-0 right-0" />
<ExpenseLogo v-else-if="chain === 'mvc'" class="absolute bottom-0 right-0" />
<IncomeLogo v-if="flow === 'Send'" class="absolute bottom-0 right-0" />
<ExpenseLogo v-else-if="flow === 'Receive'" class="absolute bottom-0 right-0" />
</template>
</div>
</template>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const signMessage = (
privateKey: mvc.PrivateKey,
encoding?: 'utf-8' | 'base64' | 'hex' | 'utf8'
) => {
const messageHash = mvc.crypto.Hash.sha256(Buffer.from(message))
const messageHash = mvc.crypto.Hash.sha256(Buffer.from('Bitcoin Signed Message:\n' + message))

let sigBuf = mvc.crypto.ECDSA.sign(messageHash, privateKey).toBuffer()

Expand Down Expand Up @@ -61,7 +61,7 @@ export const verifySignature = (
publicKey: mvc.PublicKey,
encoding?: 'utf-8' | 'base64' | 'hex' | 'utf8'
) => {
const messageHash = mvc.crypto.Hash.sha256(Buffer.from(message))
const messageHash = mvc.crypto.Hash.sha256(Buffer.from('Bitcoin Signed Message:\n' + message))

const sigDER = Buffer.from(signature, encoding || 'hex')
const sigObj = mvc.crypto.Signature.fromDER(sigDER)
Expand Down
2 changes: 1 addition & 1 deletion src/pages/wallet/Asset.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const toReceive = () => {
<template>
<div class="flex flex-col items-center space-y-6 w-full" v-if="asset">
<div class="flex flex-col items-center">
<AssetLogo :logo="asset.logo" :chain="asset.chain" :symbol="asset.symbol" type="network" />
<AssetLogo :logo="asset.logo" :chain="asset.chain" :symbol="asset.symbol" type="network" class="w-15" />

<div class="mt-3 text-2xl">
<span v-if="asset.balance"> {{ calcBalance(asset.balance.total, asset.decimal, asset.symbol) }}</span>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/wallet/Inscribe.vue
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ const changeTabIdx = (idx: number) => {

<div v-else-if="nextStep === 1" class="relative h-full space-y-4">
<FlexBox d="col" ai="center" class="space-y-4 py-1">
<AssetLogo :logo="asset.logo" :chain="asset.chain" :symbol="asset.symbol" type="network" />
<AssetLogo :logo="asset.logo" :chain="asset.chain" :symbol="asset.symbol" type="network" class="w-15" />
<div class="text-center text-base">{{ inscribeAmount }} {{ asset.symbol }}</div>
</FlexBox>
<div class="space-y-2">
Expand Down
4 changes: 2 additions & 2 deletions src/pages/wallet/Send.vue
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ async function send() {

<div class="space-y-4 w-full">
<FlexBox d="col" ai="center" :gap="3">
<AssetLogo :logo="asset?.logo" :symbol="symbol" :chain="asset.chain" type="network" />
<AssetLogo :logo="asset?.logo" :symbol="symbol" :chain="asset.chain" type="network" class="w-15"/>

<div class="text-base">{{ symbol }}</div>
</FlexBox>
Expand Down Expand Up @@ -244,7 +244,7 @@ async function send() {
<DrawerContent class="bg-white">
<DrawerHeader>
<FlexBox d="col" ai="center" :gap="4">
<AssetLogo :logo="asset.logo" :symbol="symbol" :chain="asset.chain" type="network" />
<AssetLogo :logo="asset.logo" :symbol="symbol" :chain="asset.chain" type="network" class="w-15"/>
<div class="text-base">{{ amount }} {{ symbol }}</div>
</FlexBox>
</DrawerHeader>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/wallet/SendBRC.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async function send() {

<div class="space-y-4">
<FlexBox d="col" ai="center">
<AssetLogo :logo="asset?.logo" :symbol="symbol" chain="btc" type="network" />
<AssetLogo :logo="asset?.logo" :symbol="symbol" chain="btc" type="network" class="w-15"/>

<div class="mt-3 text-base">{{ symbol }}</div>

Expand Down Expand Up @@ -188,7 +188,7 @@ async function send() {
<DrawerContent class="bg-white">
<DrawerHeader>
<FlexBox d="col" ai="center" :gap="4">
<AssetLogo :logo="asset?.logo" :symbol="symbol" chain="btc" type="network" />
<AssetLogo :logo="asset?.logo" :symbol="symbol" chain="btc" type="network" class="w-15"/>
<div class="text-base">{{ amount }} {{ symbol }}</div>
</FlexBox>
</DrawerHeader>
Expand Down
43 changes: 36 additions & 7 deletions src/pages/wallet/components/ActivityItem.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
<script lang="ts" setup>
import { computed } from 'vue'
import type { Activity } from '@/queries/activities'
import { prettifyTimestamp, prettifyTxId } from '@/lib/formatters'
import { toTx } from '@/lib/helpers'
import { getBrowserHost } from '@/lib/host'
import { FlexBox } from '@/components'
import { type Chain } from '@/lib/account'
import { type Asset } from '@/data/assets'
import { getBrowserHost } from '@/lib/host'
import AssetLogo from '@/components/AssetLogo.vue'
import type { Activity } from '@/queries/activities'
import LoadingIcon from '@/assets/icons-v3/loading.svg'
import { prettifyTimestamp, prettifyTxId } from '@/lib/formatters'
const props = defineProps<{
asset: Asset
activity: Activity
}>()
const flow = computed(() => {
const { outcome, income } = props.activity
return outcome > income ? 'Send' : 'Receive'
})
const isConfirmed = computed(() => {
if (props.asset?.contract === 'BRC-20') {
return true
Expand Down Expand Up @@ -52,8 +59,30 @@ const toActivityTx = async () => {
</script>

<template>
<div class="w-full py-3">
<AssetLogo />
<FlexBox ai="center" jc="between" class="py-3">
<FlexBox ai="center" :gap="3">
<AssetLogo
:symbol="asset.symbol"
:chain="asset.chain"
:logo="asset.logo"
type="activity"
class="w-[38px] text-lg"
:flow="flow"
/>
<div>
<div :class="['text-sm space-x-2', !isConfirmed ? 'text-orange-primary' : undefined]">
<LoadingIcon v-if="!isConfirmed" />
<span>{{ flow }}</span>
</div>
<div class="text-gray-primary text-xs">{{ prettifyTimestamp(activity.time) }}</div>
</div>
</FlexBox>
<FlexBox d="col" ai="end">
<div class="text-sm">{{ difference.display }}</div>
<div class="text-xs text-gray-primary"> {{ prettifyTxId(activity.txid) }}</div>
</FlexBox>
</FlexBox>
<!-- <div class="w-full py-3">
<div class="flex items-center justify-between">
<div class="flex items-center gap-x-2 text-green-500" v-if="isConfirmed">
Expand All @@ -75,5 +104,5 @@ const toActivityTx = async () => {
{{ prettifyTxId(activity.txid) }}
</div>
</div>
</div>
</div> -->
</template>
126 changes: 124 additions & 2 deletions src/pages/welcome/Create.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,129 @@
<script lang="ts" setup>
import { FlexBox } from '@/components'
import { ref } from 'vue'
import { mvc } from 'meta-contract'
import { addAccount } from '@/lib/account'
import passwordManager from '@/lib/password'
import { FlexBox, Button } from '@/components'
import MoreIcon from '@/assets/icons-v3/more-crytos.svg'
import BtcLogoIcon from '@/assets/images/btc-logo.svg?url'
import SpaceLogoIcon from '@/assets/icons-v3/space.svg?url'
import SuccessPNG from '@/assets/icons-v3/send-success.png'
import CreatePassword from './components/CreatePassword.vue'
import { deriveAllAddresses, type AddressType } from '@/lib/bip32-deriver'
const step = ref(1)
const stepLen = ref(2)
const successed = ref(false)
const hasPassword = ref(false)
passwordManager.has().then((_hasPassword) => {
if (_hasPassword) {
hasPassword.value = true
stepLen.value = 1
}
})
// 保存账号
const createAccount = async () => {
const mnemonic = mvc.Mnemonic.fromRandom()
const words = mnemonic.toString().split(' ')
const mnemonicStr = words.join(' ')
try {
const fullPath = `m/44'/10001'/0'/0/0`
const btcPath = fullPath
const allAddresses = deriveAllAddresses({
mnemonic: mnemonicStr,
btcPath,
mvcPath: fullPath,
})
// construct new account object
const account = {
mnemonic: mnemonicStr,
assetsDisplay: ['SPACE', 'BTC'],
mvc: {
path: fullPath,
addressType: 'P2PKH' as AddressType,
mainnetAddress: allAddresses.mvcMainnetAddress,
testnetAddress: allAddresses.mvcTestnetAddress,
},
btc: {
path: btcPath,
addressType: 'P2PKH' as AddressType,
mainnetAddress: allAddresses.btcMainnetAddress,
testnetAddress: allAddresses.btcTestnetAddress,
},
}
await addAccount(account)
successed.value = true
} catch (e) {
console.log(e)
}
}
createAccount()
</script>

<template>
<FlexBox ai="center" jc="center" class="w-screen h-screen"> Create Wallet </FlexBox>
<FlexBox d="col" class="w-full gap-20">
<FlexBox ai="center" jc="center" class="w-full h-[70px]" :gap="2">
<FlexBox
ai="center"
jc="center"
:class="['step-circle', step === _step ? 'active' : undefined]"
v-for="_step in Array.from({ length: stepLen }, (_, i) => i + 1)"
>{{ _step }}</FlexBox
>
</FlexBox>
<FlexBox jc="center" class="w-full">
<FlexBox d="col" class="w-82" v-if="!hasPassword">
<CreatePassword
:callback="
() => {
step = step + 1
hasPassword = true
successed = true
}
"
/>
</FlexBox>
<FlexBox d="col" class="w-82" v-else-if="successed">
<FlexBox d="col" ai="center">
<img :src="SuccessPNG" alt="Send Success" class="w-30" />
<h1 class="text-2xl mt-6 font-medium">Wallet created successfully</h1>
<p class="text-sm mt-12 text-gray-primary">Metalet currently supports the following cryptos</p>
<FlexBox ai="center" :gap="4" class="mt-4">
<img :src="BtcLogoIcon" class="w-11" alt="Bitcoin" />
<img :src="SpaceLogoIcon" class="w-11" alt="Space" />
<MoreIcon />
</FlexBox>
<Button type="primary" class="mt-26 w-61.5" @click="() => $router.push('/wallet')">Activate Metalet</Button>
</FlexBox>
</FlexBox>
</FlexBox>
</FlexBox>
</template>

<style scoped>
.step-circle {
@apply w-6 h-6 bg-gray-secondary text-gray-primary rounded-full text-ss cursor-pointer;
}
.step-circle.active {
@apply bg-blue-primary text-white;
}
button[aria-selected='true'] {
@apply bg-white text-blue-primary rounded-md;
}
div[role='tabpanel'][data-state='active'] {
@apply mt-4;
}
button[role='combobox'] {
@apply border-none focus:ring-0 p-0;
}
</style>
2 changes: 1 addition & 1 deletion src/pages/welcome/Import.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectVa
const step = ref(1)
const stepLen = ref(3)
const successed = ref(true)
const successed = ref(false)
const hasPassword = ref(false)
const selectableScripts = scripts.slice(0, -1)
Expand Down
1 change: 1 addition & 0 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ const routes = [
meta: {
secondaryHeader: true,
headerTitle: 'Asset',
noFooter: true,
},
},
{
Expand Down

0 comments on commit 50dbee5

Please sign in to comment.