add event callback

This commit is contained in:
liangping
2023-06-01 17:02:27 +08:00
parent 1fa6ca43bc
commit 3156dd5de6
7 changed files with 71 additions and 38 deletions
+2
View File
@@ -8,5 +8,7 @@ const store = useTxDialog();
:sender="store.sender"
:endpoint="store.endpoint"
:params="store.params"
@view="store.view"
@confirmed="store.confirmed"
></ping-tx-dialog>
</template>
+12 -8
View File
@@ -87,7 +87,11 @@ function loadAccount(address: string) {
});
});
}
loadAccount(props.address);
function updateEvent() {
loadAccount(props.address);
}
</script>
<template>
<div v-if="account">
@@ -130,7 +134,7 @@ loadAccount(props.address);
<label
for="send"
class="btn btn-primary btn-sm mr-2"
@click="dialog.open('send', {})"
@click="dialog.open('send', {}, updateEvent)"
>Send</label
>
<label
@@ -139,7 +143,7 @@ loadAccount(props.address);
@click="
dialog.open('transfer', {
chain_name: blockchain.current?.prettyName,
})
}, updateEvent)
"
>transfer</label
>
@@ -302,13 +306,13 @@ loadAccount(props.address);
<label
for="delegate"
class="btn btn-primary btn-sm mr-2"
@click="dialog.open('delegate', {})"
@click="dialog.open('delegate', {}, updateEvent)"
>Delegate</label
>
<label
for="withdraw"
class="btn btn-primary btn-sm"
@click="dialog.open('withdraw', {})"
@click="dialog.open('withdraw', {}, updateEvent)"
>Withdraw</label
>
</div>
@@ -353,7 +357,7 @@ loadAccount(props.address);
@click="
dialog.open('delegate', {
validator_address: v.delegation.validator_address,
})
}, updateEvent)
"
>delegate</label
>
@@ -363,7 +367,7 @@ loadAccount(props.address);
@click="
dialog.open('redelegate', {
validator_address: v.delegation.validator_address,
})
}, updateEvent)
"
>Redelegate</label
>
@@ -373,7 +377,7 @@ loadAccount(props.address);
@click="
dialog.open('unbond', {
validator_address: v.delegation.validator_address,
})
}, updateEvent)
"
>Unbond</label
>
+9 -6
View File
@@ -95,6 +95,10 @@ const color = computed(() => {
return 'text-red-600';
}
});
function updateState() {
walletStore.loadMyAsset()
}
</script>
<template>
@@ -216,9 +220,8 @@ const color = computed(() => {
</div>
<div class="bg-base-100 rounded mt-4 shadow">
<div class="flex items-center px-4 pt-4 pb-2 text-lg font-semibold text-main">
<div class="flex justify-between px-4 pt-4 pb-2 text-lg font-semibold text-main">
<span class="truncate" >{{ walletStore.currentAddress || 'Not Connected' }}</span>
<RouterLink v-if="walletStore.currentAddress"
class="float-right text-sm cursor-pointert link link-primary no-underline font-medium"
:to="`/${chain}/account/${walletStore.currentAddress}`">More</RouterLink>
@@ -295,11 +298,11 @@ const color = computed(() => {
<td>
<div>
<label for="delegate" class="btn !btn-xs !btn-primary btn-ghost rounded-sm mr-2"
@click="dialog.open('delegate', { validator_address: item.delegation.validator_address })">
@click="dialog.open('delegate', { validator_address: item.delegation.validator_address }, updateState)">
Delegate
</label>
<label for="withdraw" class="btn !btn-xs !btn-primary btn-ghost rounded-sm"
@click="dialog.open('withdraw', { validator_address: item.delegation.validator_address })">
@click="dialog.open('withdraw', { validator_address: item.delegation.validator_address }, updateState)">
Withdraw Rewards
</label>
</div>
@@ -311,9 +314,9 @@ const color = computed(() => {
<div class="grid grid-cols-3 gap-4 px-4 pb-6 mt-4">
<label for="PingTokenConvert" class="btn btn-primary text-white">Swap</label>
<label for="send" class="btn !bg-yes !border-yes text-white" @click="dialog.open('send', {})">Send</label>
<label for="send" class="btn !bg-yes !border-yes text-white" @click="dialog.open('send', {}, updateState)">Send</label>
<label for="delegate" class="btn !bg-info !border-info text-white"
@click="dialog.open('delegate', {})">Delegate</label>
@click="dialog.open('delegate', {}, updateState)">Delegate</label>
<RouterLink to="/wallet/receive" class="btn !bg-info !border-info text-white hidden">Receive</RouterLink>
</div>
<Teleport to="body">
+1 -1
View File
@@ -9,7 +9,7 @@ import {
import { useDistributionStore } from '@/stores/useDistributionStore';
import { useMintStore } from '@/stores/useMintStore';
import { useStakingStore } from '@/stores/useStakingStore';
import type { GovProposal, PaginatedProposals, Tally } from '@/types';
import type { Tally } from '@/types';
import numeral from 'numeral';
import { defineStore } from 'pinia';
+42 -18
View File
@@ -1,41 +1,65 @@
import { defineStore } from 'pinia';
import { useWalletStore } from './useWalletStore';
import { useBlockchain } from './useBlockchain';
import router from '@/router'
let CALLBACK: any = null
export const useTxDialog = defineStore('txDialogStore', {
state: () => {
return {
sender: "",
type: "send",
endpoint: "",
params: "",
sender: "",
type: "send",
endpoint: "",
params: "",
};
},
getters: {
walletAddress() {
return useWalletStore().currentAddress
return useWalletStore().currentAddress
},
currentEndpoint() {
return useBlockchain().endpoint?.address
return useBlockchain().endpoint?.address
},
blockchain() {
return useBlockchain()
}
},
actions: {
setParams(param: any) {
this.params = JSON.stringify(param)
this.params = JSON.stringify(param)
},
openWithArgument(type: string, sender: string, endpoint: string, param: any) {
this.type = type;
this.sender = sender;
this.endpoint = endpoint;
this.params = JSON.stringify(param)
this.type = type;
this.sender = sender;
this.endpoint = endpoint;
this.params = JSON.stringify(param)
},
open(type: string, param: any) {
this.type = type;
this.sender = this.walletAddress;
this.endpoint = this.currentEndpoint || "";
this.params = JSON.stringify(param)
// console.log("dialog:", this.$state)
open(type: string, param: any, callback?: Function) {
this.type = type;
this.sender = this.walletAddress;
this.endpoint = this.currentEndpoint || "";
this.params = JSON.stringify(param)
if(callback) {
CALLBACK = callback
}else {
CALLBACK = undefined
}
},
view(tx: {
detail: {
eventType: string,
hash: string
}
}) {
console.log(tx.detail)
if (tx.detail && tx.detail.hash) router.push({ path: `/${this.blockchain.chainName}/tx/${tx.detail.hash}` })
},
confirmed(tx: any) {
console.log("confirmed:", tx)
if(CALLBACK) {
CALLBACK()
}
}
},
});