Skip to content

Commit 78959ec

Browse files
committed
chore: release v1.8.0
1 parent 43a3462 commit 78959ec

File tree

3 files changed

+260
-1
lines changed

3 files changed

+260
-1
lines changed

components/Connection.vue

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<script setup>
2+
/** UI */
3+
import Button from "@/components/ui/Button.vue"
4+
import Spinner from "@/components/ui/Spinner.vue"
5+
import Tooltip from "@/components/ui/Tooltip.vue"
6+
7+
/** Services */
8+
import { suggestChain, getAccounts } from "@/services/keplr"
9+
10+
/** Store */
11+
import { useNotificationsStore } from "@/store/notifications"
12+
const notificationsStore = useNotificationsStore()
13+
14+
const isWalletAvailable = ref(false)
15+
16+
const isFetchingAccounts = ref(true)
17+
const account = ref()
18+
19+
onMounted(async () => {
20+
isWalletAvailable.value = !!window.keplr
21+
22+
try {
23+
const accounts = await getAccounts()
24+
if (accounts.length) account.value = accounts[0].address
25+
} catch (error) {}
26+
isFetchingAccounts.value = false
27+
})
28+
29+
const handleConnect = async () => {
30+
try {
31+
await suggestChain()
32+
} catch (error) {
33+
switch (error.message) {
34+
case "Request rejected":
35+
notificationsStore.create({
36+
notification: {
37+
type: "info",
38+
icon: "close",
39+
title: "Request rejected",
40+
description: "You canceled the Keplr wallet request",
41+
autoDestroy: true,
42+
},
43+
})
44+
break
45+
}
46+
}
47+
}
48+
49+
const test = async () => {
50+
const key = await window.keplr.getKey(OsmosisChainInfo.chainId)
51+
const protoMsgs = {
52+
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
53+
value: MsgSend.encode({
54+
fromAddress: key.bech32Address,
55+
toAddress: recipient,
56+
amount: [
57+
{
58+
denom: "uosmo",
59+
amount: DecUtils.getTenExponentN(6).mul(new Dec(amount)).truncate().toString(),
60+
},
61+
],
62+
}).finish(),
63+
}
64+
65+
try {
66+
await sendMsgs(window.keplr, OsmosisChainInfo, key.bech32Address, [protoMsgs], {
67+
amount: [{ denom: "uosmo", amount: "236" }],
68+
gas: Math.floor(gasUsed * 1.5).toString(),
69+
})
70+
} catch (e) {
71+
if (e instanceof Error) {
72+
console.log(e.message)
73+
}
74+
}
75+
}
76+
</script>
77+
78+
<template>
79+
<Tooltip v-if="isFetchingAccounts" position="end">
80+
<Button type="secondary" size="small" disabled>
81+
<Spinner size="14" />
82+
Fetching
83+
</Button>
84+
85+
<template #content>
86+
<Flex direction="column" align="end" gap="6">
87+
<Text>Receiving your accounts </Text>
88+
<Text color="tertiary" height="120" align="right" style="max-width: 200px">
89+
It's stuck? Try disabling the connection through your wallet and refresh the page
90+
</Text>
91+
<Text color="tertiary" height="120" align="right" style="max-width: 200px">
92+
Sometimes the wallet pop-up may hide behind the browser window
93+
</Text>
94+
</Flex>
95+
</template>
96+
</Tooltip>
97+
98+
<Tooltip v-else-if="!isWalletAvailable" position="end">
99+
<Button type="white" size="small" disabled> Connect </Button>
100+
101+
<template #content> Insall Keplr Wallet before connection </template>
102+
</Tooltip>
103+
104+
<Button v-else-if="!account" @click="handleConnect" type="white" size="small"> Connect </Button>
105+
106+
<Button v-else @click="test" type="secondary" size="small">
107+
<Icon name="address" size="14" color="primary" />
108+
celestia ... {{ account.slice(-4) }}
109+
</Button>
110+
</template>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "celestia-explorer",
3-
"version": "1.7.0",
3+
"version": "1.8.0",
44
"packageManager": "pnpm@8.7.4",
55
"homepage": "https://celenium.io/",
66
"license": "MIT",

services/keplr.js

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import { TendermintTxTracer } from "@keplr-wallet/cosmos"
2+
3+
export const suggestChain = () => {
4+
return new Promise(async (resolve, reject) => {
5+
try {
6+
await window.keplr.experimentalSuggestChain({
7+
chainId: "mocha-4",
8+
chainName: "Mocha Testnet",
9+
rpc: "https://rpc-mocha.pops.one/",
10+
rest: "https://api-mocha.pops.one/",
11+
bip44: {
12+
coinType: 118,
13+
},
14+
bech32Config: {
15+
bech32PrefixAccAddr: "celestia",
16+
bech32PrefixAccPub: "celestia" + "pub",
17+
bech32PrefixValAddr: "celestia" + "valoper",
18+
bech32PrefixValPub: "celestia" + "valoperpub",
19+
bech32PrefixConsAddr: "celestia" + "valcons",
20+
bech32PrefixConsPub: "celestia" + "valconspub",
21+
},
22+
currencies: [
23+
{
24+
coinDenom: "TIA",
25+
coinMinimalDenom: "utia",
26+
coinDecimals: 6,
27+
coinGeckoId: "celestia",
28+
},
29+
],
30+
feeCurrencies: [
31+
{
32+
coinDenom: "TIA",
33+
coinMinimalDenom: "utia",
34+
coinDecimals: 6,
35+
coinGeckoId: "celestia",
36+
gasPriceStep: {
37+
low: 0.01,
38+
average: 0.02,
39+
high: 0.1,
40+
},
41+
},
42+
],
43+
stakeCurrency: {
44+
coinDenom: "TIA",
45+
coinMinimalDenom: "utia",
46+
coinDecimals: 6,
47+
coinGeckoId: "celestia",
48+
},
49+
})
50+
51+
await window.keplr.enable("mocha-4")
52+
53+
resolve({ success: true })
54+
} catch (error) {
55+
reject({ success: false, message: error.message })
56+
}
57+
})
58+
}
59+
60+
export const getAccounts = () => {
61+
return new Promise(async (resolve, reject) => {
62+
try {
63+
const offlineSigner = window.getOfflineSigner("mocha-4")
64+
const accounts = await offlineSigner.getAccounts()
65+
resolve(accounts)
66+
} catch (error) {
67+
reject(error.message)
68+
}
69+
})
70+
}
71+
72+
export const sendMsgs = async (sender, proto, fee, memo = "") => {
73+
const account = await fetchAccountInfo(sender)
74+
const { pubKey } = await window.keplr.getKey("mocha-4")
75+
76+
if (account) {
77+
const signDoc = {
78+
bodyBytes: TxBody.encode(
79+
TxBody.fromPartial({
80+
messages: proto,
81+
memo,
82+
}),
83+
).finish(),
84+
authInfoBytes: AuthInfo.encode({
85+
signerInfos: [
86+
{
87+
publicKey: {
88+
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
89+
value: PubKey.encode({
90+
key: pubKey,
91+
}).finish(),
92+
},
93+
modeInfo: {
94+
single: {
95+
mode: SignMode.SIGN_MODE_DIRECT,
96+
},
97+
multi: undefined,
98+
},
99+
sequence: account.sequence,
100+
},
101+
],
102+
fee: Fee.fromPartial({
103+
amount: fee.amount.map((coin) => {
104+
return {
105+
denom: coin.denom,
106+
amount: coin.amount.toString(),
107+
}
108+
}),
109+
gasLimit: fee.gas,
110+
}),
111+
}).finish(),
112+
chainId: "mocha-4",
113+
accountNumber: Long.fromString(account.account_number),
114+
}
115+
116+
const signed = await window.keplr.signDirect("mocha-4", sender, signDoc)
117+
118+
const signedTx = {
119+
tx: TxRaw.encode({
120+
bodyBytes: signed.signed.bodyBytes,
121+
authInfoBytes: signed.signed.authInfoBytes,
122+
signatures: [Buffer.from(signed.signature.signature, "base64")],
123+
}).finish(),
124+
signDoc: signed.signed,
125+
}
126+
127+
const txHash = await broadcastTxSync(window.keplr, "mocha-4", signedTx.tx)
128+
const txTracer = new TendermintTxTracer("https://rpc-mocha.pops.one/", "/websocket")
129+
txTracer.traceTx(txHash).then((tx) => {
130+
alert("Transaction commit successfully")
131+
})
132+
}
133+
}
134+
135+
export const fetchAccountInfo = async (address) => {
136+
try {
137+
const uri = `https://api-mocha.pops.one/cosmos/auth/v1beta1/accounts/${address}`
138+
const response = await fetch(uri)
139+
140+
return response.account
141+
} catch (e) {
142+
console.error("This may be a new account. Please send some tokens to this account first.")
143+
return undefined
144+
}
145+
}
146+
147+
export const broadcastTxSync = async (tx) => {
148+
return window.keplr.sendTx("mocha-4", tx, "sync")
149+
}

0 commit comments

Comments
 (0)