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

View File

@ -35,7 +35,7 @@
"md-editor-v3": "^2.8.1",
"numeral": "^2.0.6",
"osmojs": "^14.0.0-rc.0",
"ping-widget": "^0.0.30",
"ping-widget": "^0.0.31",
"pinia": "^2.0.28",
"postcss": "^8.4.23",
"qrcode": "^1.5.3",

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>

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
>

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">

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';

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()
}
}
},
});

View File

@ -5476,10 +5476,10 @@ pify@^3.0.0:
resolved "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz"
integrity sha512-C3FsVNH1udSEX48gGX1xfvwTWfsYWj5U+8/uK15BGzIGrKoUpghX8hWZwa/OFnakBiiVNmBvemTJR5mcy7iPcg==
ping-widget@^0.0.30:
version "0.0.30"
resolved "https://registry.yarnpkg.com/ping-widget/-/ping-widget-0.0.30.tgz#f417cff47fb8a95e443e953bc5eb3c912801f605"
integrity sha512-bKa47dHNqUw/TaRBbjxQkb5+yXMwEq0+EiIs3b9Q5/0HlFcs19rdzH/RDQj4S3tpClOX7N5hTpAFikOInHq20g==
ping-widget@^0.0.31:
version "0.0.31"
resolved "https://registry.yarnpkg.com/ping-widget/-/ping-widget-0.0.31.tgz#79e8e7d8cbcfd7c15b09959e30a347dadf0ab989"
integrity sha512-vWv6F+1uXrsohBCA1GwAK4p2QMyvV2Y0/HW2lVWWiYhXYdbon3Q1wwgLnBcXspy6lN9x67+WEXVGE5Jv95g4MA==
dependencies:
"@cosmjs/amino" "^0.30.1"
"@cosmjs/cosmwasm-stargate" "^0.30.1"