@mictonode/widget 0.3.16 → 0.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/FUNDING.yml +3 -3
- package/.github/workflows/npm-publish.yml +34 -34
- package/.prettierrc.json +9 -9
- package/.vscode/extensions.json +3 -3
- package/LICENSE +674 -674
- package/README.md +41 -41
- package/dist/{main-d0e5d1e4.js → main-465ae991.js} +151 -149
- package/dist/ping-widget.js +2 -2
- package/dist/ping-widget.umd.cjs +17 -17
- package/dist/{query.lcd-3d4d3495.js → query.lcd-d9c6163c.js} +1 -1
- package/dist/{query.rpc.Query-b7807c29.js → query.rpc.Query-a479e6f9.js} +1 -1
- package/dist/{tx.rpc.msg-59c3408a.js → tx.rpc.msg-7444045d.js} +1 -1
- package/example/.vscode/extensions.json +3 -3
- package/example/README.md +7 -7
- package/example/index.html +12 -12
- package/example/package.json +19 -19
- package/example/pnpm-lock.yaml +465 -465
- package/example/public/cdn.html +19 -19
- package/example/src/App.vue +73 -73
- package/example/src/main.js +4 -4
- package/example/vite.config.js +7 -7
- package/index.html +12 -12
- package/lib/components/ConnectWallet/index.vue +262 -262
- package/lib/components/TokenConvert/index.vue +1033 -1033
- package/lib/components/TokenConvert/tokens.ts +36 -36
- package/lib/components/TxDialog/index.vue +8 -8
- package/lib/components/TxDialog/messages/Delegate.vue +174 -174
- package/lib/components/TxDialog/messages/Deposit.vue +96 -96
- package/lib/components/TxDialog/messages/Redelegate.vue +160 -160
- package/lib/components/TxDialog/messages/Send.vue +142 -142
- package/lib/components/TxDialog/messages/Transfer.vue +248 -248
- package/lib/components/TxDialog/messages/Unbond.vue +103 -103
- package/lib/components/TxDialog/messages/Vote.vue +62 -62
- package/lib/components/TxDialog/messages/Withdraw.vue +55 -55
- package/lib/components/TxDialog/messages/WithdrawCommission.vue +74 -74
- package/lib/components/TxDialog/wasm/ClearAdmin.vue +55 -55
- package/lib/components/TxDialog/wasm/ExecuteContract.vue +98 -98
- package/lib/components/TxDialog/wasm/InstantiateContract.vue +108 -108
- package/lib/components/TxDialog/wasm/MigrateContract.vue +76 -76
- package/lib/components/TxDialog/wasm/MigrateContract2.vue +76 -76
- package/lib/components/TxDialog/wasm/StoreCode.vue +100 -100
- package/lib/components/TxDialog/wasm/UpdateAdmin.vue +74 -74
- package/lib/main.css +132 -7
- package/lib/main.ts +23 -23
- package/lib/utils/TokenUnitConverter.ts +44 -44
- package/lib/utils/format.ts +16 -16
- package/lib/utils/http.ts +154 -154
- package/lib/utils/type.ts +56 -56
- package/lib/wallet/EthermintMessageAdapter.ts +135 -135
- package/lib/wallet/UniClient.ts +144 -144
- package/lib/wallet/Wallet.ts +142 -142
- package/lib/wallet/wallets/KeplerWallet.ts +141 -141
- package/lib/wallet/wallets/LeapWallet.ts +141 -141
- package/lib/wallet/wallets/LedgerWallet.ts +202 -202
- package/lib/wallet/wallets/MetamaskSnapWallet.ts +105 -105
- package/lib/wallet/wallets/MetamaskWallet.ts +173 -173
- package/lib/wallet/wallets/OKXWallet.ts +202 -202
- package/lib/wallet/wallets/UnisatWallet.ts +198 -198
- package/package.json +3 -3
- package/postcss.config.js +6 -6
- package/src/App.vue +225 -225
- package/src/main.ts +7 -4
- package/src/styles/design-system.css +150 -0
- package/src/vite-env.d.ts +1 -1
- package/tailwind.config.js +211 -34
- package/tsconfig.json +25 -25
- package/tsconfig.node.json +10 -10
- package/vite.config.ts +62 -62
- package/vue-shim.d.ts +6 -6
package/lib/main.css
CHANGED
|
@@ -1,7 +1,132 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
@tailwind
|
|
4
|
-
|
|
5
|
-
.
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
/* ============================================================
|
|
2
|
+
S4 4.20 — Explorer DS Font Integration
|
|
3
|
+
@import must precede @tailwind directives
|
|
4
|
+
============================================================ */
|
|
5
|
+
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');
|
|
6
|
+
|
|
7
|
+
@tailwind base;
|
|
8
|
+
@tailwind components;
|
|
9
|
+
@tailwind utilities;
|
|
10
|
+
|
|
11
|
+
body {
|
|
12
|
+
font-family: 'Inter', system-ui, -apple-system, sans-serif;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
h1, h2, h3, h4, h5, h6,
|
|
16
|
+
.text-lg, .text-xl, .text-2xl {
|
|
17
|
+
font-family: 'Space Grotesk', 'Inter', system-ui, sans-serif;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
code, pre, .font-mono {
|
|
21
|
+
font-family: 'JetBrains Mono', 'Fira Code', monospace;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* ============================================================
|
|
25
|
+
S4 4.20 — DaisyUI Glassmorphism Override (Dark Mode)
|
|
26
|
+
Aligns DaisyUI components with Explorer Design System
|
|
27
|
+
============================================================ */
|
|
28
|
+
|
|
29
|
+
/* Input focus reset */
|
|
30
|
+
.input:focus {
|
|
31
|
+
outline: none;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/* Modal → Glass Panel */
|
|
35
|
+
.dark .modal-box {
|
|
36
|
+
background: rgba(15, 20, 25, 0.85);
|
|
37
|
+
backdrop-filter: blur(16px);
|
|
38
|
+
-webkit-backdrop-filter: blur(16px);
|
|
39
|
+
border: 1px solid rgba(255, 255, 255, 0.08);
|
|
40
|
+
border-radius: 16px;
|
|
41
|
+
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5),
|
|
42
|
+
0 0 0 1px rgba(255, 255, 255, 0.05);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* Buttons → Gradient */
|
|
46
|
+
.dark .btn-primary,
|
|
47
|
+
.dark .btn.btn-primary {
|
|
48
|
+
background: linear-gradient(135deg, lch(52% 70% 250deg), lch(55% 65% 245deg));
|
|
49
|
+
border: 1px solid rgba(0, 102, 255, 0.2);
|
|
50
|
+
color: #ffffff;
|
|
51
|
+
transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.dark .btn-primary:hover,
|
|
55
|
+
.dark .btn.btn-primary:hover {
|
|
56
|
+
transform: translateY(-1px);
|
|
57
|
+
box-shadow: 0 8px 25px -5px rgba(0, 102, 255, 0.4),
|
|
58
|
+
0 0 0 1px rgba(0, 102, 255, 0.1);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.dark .btn-primary:active,
|
|
62
|
+
.dark .btn.btn-primary:active {
|
|
63
|
+
transform: scale(0.97);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* Close button (circle btn) */
|
|
67
|
+
.dark .btn.btn-sm.btn-circle {
|
|
68
|
+
background: rgba(255, 255, 255, 0.1);
|
|
69
|
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
70
|
+
color: #9ca3af;
|
|
71
|
+
transition: all 0.15s ease;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.dark .btn.btn-sm.btn-circle:hover {
|
|
75
|
+
background: rgba(255, 255, 255, 0.15);
|
|
76
|
+
color: #e5e7eb;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* Inputs → Glass Input */
|
|
80
|
+
.dark .input,
|
|
81
|
+
.dark .select,
|
|
82
|
+
.dark .textarea {
|
|
83
|
+
background: rgba(255, 255, 255, 0.05);
|
|
84
|
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
85
|
+
color: #e5e7eb;
|
|
86
|
+
transition: border-color 0.2s ease, box-shadow 0.2s ease;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.dark .input:focus,
|
|
90
|
+
.dark .select:focus,
|
|
91
|
+
.dark .textarea:focus {
|
|
92
|
+
border-color: #0066ff;
|
|
93
|
+
box-shadow: 0 0 0 3px rgba(0, 102, 255, 0.15);
|
|
94
|
+
outline: none;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.dark .input::placeholder,
|
|
98
|
+
.dark .textarea::placeholder {
|
|
99
|
+
color: #6b7280;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/* Dropdown → Glass Dropdown */
|
|
103
|
+
.dark .dropdown-content {
|
|
104
|
+
background: rgba(15, 20, 25, 0.9);
|
|
105
|
+
backdrop-filter: blur(12px);
|
|
106
|
+
-webkit-backdrop-filter: blur(12px);
|
|
107
|
+
border: 1px solid rgba(255, 255, 255, 0.08);
|
|
108
|
+
border-radius: 12px;
|
|
109
|
+
box-shadow: 0 20px 40px -8px rgba(0, 0, 0, 0.5);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/* Alert → Glass Alert */
|
|
113
|
+
.dark .alert {
|
|
114
|
+
backdrop-filter: blur(8px);
|
|
115
|
+
-webkit-backdrop-filter: blur(8px);
|
|
116
|
+
border: 1px solid rgba(255, 255, 255, 0.06);
|
|
117
|
+
border-radius: 12px;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* Toast → Glass Toast */
|
|
121
|
+
.dark .toast {
|
|
122
|
+
backdrop-filter: blur(8px);
|
|
123
|
+
-webkit-backdrop-filter: blur(8px);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/* Card (used in TokenConvert dropdown) */
|
|
127
|
+
.dark .card.dropdown-content {
|
|
128
|
+
background: rgba(15, 20, 25, 0.9);
|
|
129
|
+
backdrop-filter: blur(12px);
|
|
130
|
+
-webkit-backdrop-filter: blur(12px);
|
|
131
|
+
border: 1px solid rgba(255, 255, 255, 0.08);
|
|
132
|
+
}
|
package/lib/main.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import './main.css';
|
|
2
|
-
import { createApp, h } from 'vue';
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
import wrapper from 'vue3-webcomponent-wrapper';
|
|
5
|
-
|
|
6
|
-
import TxDialog from './components/TxDialog/index.vue';
|
|
7
|
-
import ConnectWallet from './components/ConnectWallet/index.vue';
|
|
8
|
-
import TokenConvert from './components/TokenConvert/index.vue';
|
|
9
|
-
|
|
10
|
-
function registry(name: string, module: any) {
|
|
11
|
-
if (!window.customElements.get(name)) {
|
|
12
|
-
const component = wrapper(module, createApp, h);
|
|
13
|
-
window.customElements.define(name, component);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
registry('ping-tx-dialog', TxDialog)
|
|
18
|
-
registry('ping-connect-wallet', ConnectWallet)
|
|
19
|
-
registry('ping-token-convert', TokenConvert)
|
|
20
|
-
|
|
21
|
-
export default {
|
|
22
|
-
version: '0.0.5',
|
|
23
|
-
};
|
|
1
|
+
import './main.css';
|
|
2
|
+
import { createApp, h } from 'vue';
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import wrapper from 'vue3-webcomponent-wrapper';
|
|
5
|
+
|
|
6
|
+
import TxDialog from './components/TxDialog/index.vue';
|
|
7
|
+
import ConnectWallet from './components/ConnectWallet/index.vue';
|
|
8
|
+
import TokenConvert from './components/TokenConvert/index.vue';
|
|
9
|
+
|
|
10
|
+
function registry(name: string, module: any) {
|
|
11
|
+
if (!window.customElements.get(name)) {
|
|
12
|
+
const component = wrapper(module, createApp, h);
|
|
13
|
+
window.customElements.define(name, component);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
registry('ping-tx-dialog', TxDialog)
|
|
18
|
+
registry('ping-connect-wallet', ConnectWallet)
|
|
19
|
+
registry('ping-token-convert', TokenConvert)
|
|
20
|
+
|
|
21
|
+
export default {
|
|
22
|
+
version: '0.0.5',
|
|
23
|
+
};
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { Coin, CoinMetadata } from "./type";
|
|
2
|
-
import BigNumber from 'bignumber.js';
|
|
3
|
-
|
|
4
|
-
export class TokenUnitConverter {
|
|
5
|
-
metadata: Record<string, CoinMetadata>
|
|
6
|
-
constructor(metas?: Record<string, CoinMetadata> ) {
|
|
7
|
-
this.metadata = metas? metas: {}
|
|
8
|
-
}
|
|
9
|
-
addMetadata(denom: string, meta: CoinMetadata) {
|
|
10
|
-
this.metadata[denom] = meta
|
|
11
|
-
}
|
|
12
|
-
baseToDisplay(token: Coin, decimal = 6) {
|
|
13
|
-
const meta = this.metadata[token.denom]
|
|
14
|
-
if(!meta) return token
|
|
15
|
-
const unit = meta.denom_units.find(unit => unit.denom === meta.display)
|
|
16
|
-
if(!unit) return token
|
|
17
|
-
const amount = BigNumber(Number(token.amount)).div(BigNumber(10).pow(unit.exponent))
|
|
18
|
-
return {
|
|
19
|
-
amount: amount.toFixed(decimal),
|
|
20
|
-
denom: unit.denom.toUpperCase()
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
baseToUnit(token: Coin, unitName: string, decimal = 6) {
|
|
24
|
-
const meta = this.metadata[token.denom]
|
|
25
|
-
if(!meta) return token
|
|
26
|
-
const unit = meta.denom_units.find(unit => unit.denom === unitName)
|
|
27
|
-
if(!unit) return token
|
|
28
|
-
const amount = BigNumber(Number(token.amount)).div(BigNumber(10).pow(unit.exponent))
|
|
29
|
-
return {
|
|
30
|
-
amount: parseFloat(amount.toFixed(decimal)).toString(),
|
|
31
|
-
denom: unit.denom
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
displayToBase(baseDenom: string, display: Coin) {
|
|
35
|
-
const meta = this.metadata[baseDenom]
|
|
36
|
-
if(!meta) return display
|
|
37
|
-
const unit = meta.denom_units.find(unit => unit.denom === display.denom)
|
|
38
|
-
if(!unit) return display
|
|
39
|
-
const amount = BigNumber(Number(display.amount)).times(BigNumber(10).pow(unit.exponent))
|
|
40
|
-
return {
|
|
41
|
-
amount: amount.toFixed(),
|
|
42
|
-
denom: baseDenom
|
|
43
|
-
}
|
|
44
|
-
}
|
|
1
|
+
import { Coin, CoinMetadata } from "./type";
|
|
2
|
+
import BigNumber from 'bignumber.js';
|
|
3
|
+
|
|
4
|
+
export class TokenUnitConverter {
|
|
5
|
+
metadata: Record<string, CoinMetadata>
|
|
6
|
+
constructor(metas?: Record<string, CoinMetadata> ) {
|
|
7
|
+
this.metadata = metas? metas: {}
|
|
8
|
+
}
|
|
9
|
+
addMetadata(denom: string, meta: CoinMetadata) {
|
|
10
|
+
this.metadata[denom] = meta
|
|
11
|
+
}
|
|
12
|
+
baseToDisplay(token: Coin, decimal = 6) {
|
|
13
|
+
const meta = this.metadata[token.denom]
|
|
14
|
+
if(!meta) return token
|
|
15
|
+
const unit = meta.denom_units.find(unit => unit.denom === meta.display)
|
|
16
|
+
if(!unit) return token
|
|
17
|
+
const amount = BigNumber(Number(token.amount)).div(BigNumber(10).pow(unit.exponent))
|
|
18
|
+
return {
|
|
19
|
+
amount: amount.toFixed(decimal),
|
|
20
|
+
denom: unit.denom.toUpperCase()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
baseToUnit(token: Coin, unitName: string, decimal = 6) {
|
|
24
|
+
const meta = this.metadata[token.denom]
|
|
25
|
+
if(!meta) return token
|
|
26
|
+
const unit = meta.denom_units.find(unit => unit.denom === unitName)
|
|
27
|
+
if(!unit) return token
|
|
28
|
+
const amount = BigNumber(Number(token.amount)).div(BigNumber(10).pow(unit.exponent))
|
|
29
|
+
return {
|
|
30
|
+
amount: parseFloat(amount.toFixed(decimal)).toString(),
|
|
31
|
+
denom: unit.denom
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
displayToBase(baseDenom: string, display: Coin) {
|
|
35
|
+
const meta = this.metadata[baseDenom]
|
|
36
|
+
if(!meta) return display
|
|
37
|
+
const unit = meta.denom_units.find(unit => unit.denom === display.denom)
|
|
38
|
+
if(!unit) return display
|
|
39
|
+
const amount = BigNumber(Number(display.amount)).times(BigNumber(10).pow(unit.exponent))
|
|
40
|
+
return {
|
|
41
|
+
amount: amount.toFixed(),
|
|
42
|
+
denom: baseDenom
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
45
|
}
|
package/lib/utils/format.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { fromBech32, toBech32, fromHex, toHex } from '@cosmjs/encoding'
|
|
2
|
-
|
|
3
|
-
export const ethToEthermint = (ethAddress: string, prefix: string) => {
|
|
4
|
-
const data = fromHex(ethAddress.replace("0x", ""))
|
|
5
|
-
return toBech32(prefix, data)
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const ethermintToEth = (ethermintAddress: string) => {
|
|
9
|
-
const { data } = fromBech32(ethermintAddress)
|
|
10
|
-
return `0x${toHex(data)}`
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function decimal2percent(v?: string) {
|
|
14
|
-
return v ? parseFloat((Number(v) * 100).toFixed(2)) : ''
|
|
15
|
-
}
|
|
16
|
-
|
|
1
|
+
import { fromBech32, toBech32, fromHex, toHex } from '@cosmjs/encoding'
|
|
2
|
+
|
|
3
|
+
export const ethToEthermint = (ethAddress: string, prefix: string) => {
|
|
4
|
+
const data = fromHex(ethAddress.replace("0x", ""))
|
|
5
|
+
return toBech32(prefix, data)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const ethermintToEth = (ethermintAddress: string) => {
|
|
9
|
+
const { data } = fromBech32(ethermintAddress)
|
|
10
|
+
return `0x${toHex(data)}`
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function decimal2percent(v?: string) {
|
|
14
|
+
return v ? parseFloat((Number(v) * 100).toFixed(2)) : ''
|
|
15
|
+
}
|
|
16
|
+
|
package/lib/utils/http.ts
CHANGED
|
@@ -1,155 +1,155 @@
|
|
|
1
|
-
import fetch from 'cross-fetch'
|
|
2
|
-
import { Coin, CoinMetadata, TxResponse } from './type'
|
|
3
|
-
|
|
4
|
-
export async function get(url: string) {
|
|
5
|
-
return (await fetch(url)).json()
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export async function post(url: string, data: any) {
|
|
9
|
-
const response = await fetch(url, {
|
|
10
|
-
method: 'POST', // *GET, POST, PUT, DELETE, etc.
|
|
11
|
-
// mode: 'cors', // no-cors, *cors, same-origin
|
|
12
|
-
// credentials: 'same-origin', // redirect: 'follow', // manual, *follow, error
|
|
13
|
-
// referrerPolicy: 'origin', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
|
|
14
|
-
headers: {
|
|
15
|
-
'Content-Type': 'text/plain',
|
|
16
|
-
Accept: '*/*',
|
|
17
|
-
// 'Accept-Encoding': 'gzip, deflate, br',
|
|
18
|
-
},
|
|
19
|
-
body: JSON.stringify(data), // body data type must match "Content-Type" header
|
|
20
|
-
})
|
|
21
|
-
// const response = axios.post((config ? config.api : this.config.api) + url, data)
|
|
22
|
-
return response.json() // parses JSON response into native JavaScript objects
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function findField(obj: any, name: string) {
|
|
26
|
-
|
|
27
|
-
if(!obj) return undefined
|
|
28
|
-
|
|
29
|
-
const list = Object.keys(obj).filter(x => x && !x.startsWith("@"))
|
|
30
|
-
if(list.includes(name)) {
|
|
31
|
-
return obj[name]
|
|
32
|
-
}
|
|
33
|
-
for(let i = 0; i < list.length; i++) {
|
|
34
|
-
const field = obj[list[i]]
|
|
35
|
-
if(typeof field === 'string') continue
|
|
36
|
-
if(Array.isArray(field)) continue
|
|
37
|
-
|
|
38
|
-
const sub = findField(field, name)
|
|
39
|
-
if(sub) return sub
|
|
40
|
-
}
|
|
41
|
-
return undefined
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// /cosmos/base/tendermint/v1beta1/blocks/latest
|
|
45
|
-
export async function getLatestBlock(endpoint: string) {
|
|
46
|
-
const url = `${endpoint}/cosmos/base/tendermint/v1beta1/blocks/latest`
|
|
47
|
-
return get(url)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export async function getAccount(endpoint: string, address: string) {
|
|
51
|
-
const url = `${endpoint}/cosmos/auth/v1beta1/accounts/${address}`
|
|
52
|
-
try{
|
|
53
|
-
const res = await get(url)
|
|
54
|
-
return {
|
|
55
|
-
account: {
|
|
56
|
-
account_number: findField(res, "account_number"),
|
|
57
|
-
sequence: findField(res, "sequence")
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}catch(err) {
|
|
61
|
-
throw new Error(err)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export async function getBalance(endpoint: string, address: string): Promise<{balances: Coin[]}> {
|
|
67
|
-
const url = `${endpoint}/cosmos/bank/v1beta1/balances/${address}`
|
|
68
|
-
return get(url)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export async function getBalanceMetadata(endpoint: string, denom: string): Promise<{metadata: CoinMetadata }> {
|
|
72
|
-
const url = `${endpoint}/cosmos/bank/v1beta1/denoms_metadata/${denom}`
|
|
73
|
-
return get(url)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export async function getIBCDenomMetadata(denom: string): Promise<CoinMetadata> {
|
|
77
|
-
const url = `https://metadata.ping.pub/metadata/${denom.replace("ibc/", "")}`
|
|
78
|
-
return get(url)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export async function getCoinMetadata(endpoint: string, denom: string) {
|
|
82
|
-
const url = `${endpoint}/cosmos/bank/v1beta1/denoms_metadata/${denom}`
|
|
83
|
-
return get(url)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export async function getDelegateRewards(endpoint: string, address: string) {
|
|
87
|
-
const url = `${endpoint}/cosmos/distribution/v1beta1/delegators/${address}/rewards`
|
|
88
|
-
return get(url)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export async function getDelegations(endpoint: string, validator_addr: string, address: string) : Promise< {
|
|
92
|
-
delegation_response: {
|
|
93
|
-
balance: Coin,
|
|
94
|
-
delegation: {
|
|
95
|
-
delegator_address: string,
|
|
96
|
-
shares: string,
|
|
97
|
-
validator_address: string
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}> {
|
|
101
|
-
const url = `${endpoint}/cosmos/staking/v1beta1/validators/${validator_addr}/delegations/${address}`
|
|
102
|
-
return get(url)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export async function getActiveValidators(endpoint: string) {
|
|
106
|
-
const url = `${endpoint}/cosmos/staking/v1beta1/validators?pagination.limit=300&status=BOND_STATUS_BONDED`
|
|
107
|
-
return get(url)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export async function getInactiveValidators(endpoint: string) {
|
|
111
|
-
const url = `${endpoint}/cosmos/staking/v1beta1/validators?pagination.limit=300&status=BOND_STATUS_UNBONDED`
|
|
112
|
-
return get(url)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// /ibc/apps/transfer/v1/denom_traces/{hash}
|
|
116
|
-
export async function getDenomTraces(endpoint: string, hash: string) : Promise<{
|
|
117
|
-
denom_trace: {
|
|
118
|
-
path: string;
|
|
119
|
-
base_denom: string;
|
|
120
|
-
};
|
|
121
|
-
}> {
|
|
122
|
-
const url = `${endpoint}/ibc/apps/transfer/v1/denom_traces/${hash}`
|
|
123
|
-
return get(url)
|
|
124
|
-
}
|
|
125
|
-
// /cosmos/tx/v1beta1/txs/{hash}
|
|
126
|
-
export async function getTxByHash(endpoint: string, hash: string) : Promise<{
|
|
127
|
-
tx_response: TxResponse;
|
|
128
|
-
}> {
|
|
129
|
-
const url = `${endpoint}/cosmos/tx/v1beta1/txs/${hash}`
|
|
130
|
-
return get(url)
|
|
131
|
-
}
|
|
132
|
-
// /cosmos/staking/v1beta1/params
|
|
133
|
-
export async function getStakingParam(endpoint: string) : Promise<{
|
|
134
|
-
params: {
|
|
135
|
-
unbonding_time: string;
|
|
136
|
-
max_validators: number;
|
|
137
|
-
max_entries: number;
|
|
138
|
-
historical_entries: number;
|
|
139
|
-
bond_denom: string;
|
|
140
|
-
};
|
|
141
|
-
}> {
|
|
142
|
-
const url = `${endpoint}/cosmos/staking/v1beta1/params`
|
|
143
|
-
return get(url)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export async function getOsmosisPools(endpoint: string) {
|
|
147
|
-
const url = `${endpoint}/osmosis/gamm/v1beta1/pools?pagination.limit=1000`
|
|
148
|
-
return get(url)
|
|
149
|
-
}
|
|
150
|
-
// https://lcd.osmosis.zone
|
|
151
|
-
// /osmosis/gamm/v1beta1/{pool_id}/estimate/swap_exact_amount_in
|
|
152
|
-
export async function estimateSwapAmountIn(endpoint: string, poolId: string, token: Coin) {
|
|
153
|
-
const url = `${endpoint}/osmosis/gamm/v1beta1/${poolId}/estimate/swap_exact_amount_in?token_in=${token.amount}${token.denom}`
|
|
154
|
-
return get(url)
|
|
1
|
+
import fetch from 'cross-fetch'
|
|
2
|
+
import { Coin, CoinMetadata, TxResponse } from './type'
|
|
3
|
+
|
|
4
|
+
export async function get(url: string) {
|
|
5
|
+
return (await fetch(url)).json()
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export async function post(url: string, data: any) {
|
|
9
|
+
const response = await fetch(url, {
|
|
10
|
+
method: 'POST', // *GET, POST, PUT, DELETE, etc.
|
|
11
|
+
// mode: 'cors', // no-cors, *cors, same-origin
|
|
12
|
+
// credentials: 'same-origin', // redirect: 'follow', // manual, *follow, error
|
|
13
|
+
// referrerPolicy: 'origin', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
|
|
14
|
+
headers: {
|
|
15
|
+
'Content-Type': 'text/plain',
|
|
16
|
+
Accept: '*/*',
|
|
17
|
+
// 'Accept-Encoding': 'gzip, deflate, br',
|
|
18
|
+
},
|
|
19
|
+
body: JSON.stringify(data), // body data type must match "Content-Type" header
|
|
20
|
+
})
|
|
21
|
+
// const response = axios.post((config ? config.api : this.config.api) + url, data)
|
|
22
|
+
return response.json() // parses JSON response into native JavaScript objects
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function findField(obj: any, name: string) {
|
|
26
|
+
|
|
27
|
+
if(!obj) return undefined
|
|
28
|
+
|
|
29
|
+
const list = Object.keys(obj).filter(x => x && !x.startsWith("@"))
|
|
30
|
+
if(list.includes(name)) {
|
|
31
|
+
return obj[name]
|
|
32
|
+
}
|
|
33
|
+
for(let i = 0; i < list.length; i++) {
|
|
34
|
+
const field = obj[list[i]]
|
|
35
|
+
if(typeof field === 'string') continue
|
|
36
|
+
if(Array.isArray(field)) continue
|
|
37
|
+
|
|
38
|
+
const sub = findField(field, name)
|
|
39
|
+
if(sub) return sub
|
|
40
|
+
}
|
|
41
|
+
return undefined
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// /cosmos/base/tendermint/v1beta1/blocks/latest
|
|
45
|
+
export async function getLatestBlock(endpoint: string) {
|
|
46
|
+
const url = `${endpoint}/cosmos/base/tendermint/v1beta1/blocks/latest`
|
|
47
|
+
return get(url)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function getAccount(endpoint: string, address: string) {
|
|
51
|
+
const url = `${endpoint}/cosmos/auth/v1beta1/accounts/${address}`
|
|
52
|
+
try{
|
|
53
|
+
const res = await get(url)
|
|
54
|
+
return {
|
|
55
|
+
account: {
|
|
56
|
+
account_number: findField(res, "account_number"),
|
|
57
|
+
sequence: findField(res, "sequence")
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}catch(err) {
|
|
61
|
+
throw new Error(err)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function getBalance(endpoint: string, address: string): Promise<{balances: Coin[]}> {
|
|
67
|
+
const url = `${endpoint}/cosmos/bank/v1beta1/balances/${address}`
|
|
68
|
+
return get(url)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function getBalanceMetadata(endpoint: string, denom: string): Promise<{metadata: CoinMetadata }> {
|
|
72
|
+
const url = `${endpoint}/cosmos/bank/v1beta1/denoms_metadata/${denom}`
|
|
73
|
+
return get(url)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export async function getIBCDenomMetadata(denom: string): Promise<CoinMetadata> {
|
|
77
|
+
const url = `https://metadata.ping.pub/metadata/${denom.replace("ibc/", "")}`
|
|
78
|
+
return get(url)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export async function getCoinMetadata(endpoint: string, denom: string) {
|
|
82
|
+
const url = `${endpoint}/cosmos/bank/v1beta1/denoms_metadata/${denom}`
|
|
83
|
+
return get(url)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function getDelegateRewards(endpoint: string, address: string) {
|
|
87
|
+
const url = `${endpoint}/cosmos/distribution/v1beta1/delegators/${address}/rewards`
|
|
88
|
+
return get(url)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export async function getDelegations(endpoint: string, validator_addr: string, address: string) : Promise< {
|
|
92
|
+
delegation_response: {
|
|
93
|
+
balance: Coin,
|
|
94
|
+
delegation: {
|
|
95
|
+
delegator_address: string,
|
|
96
|
+
shares: string,
|
|
97
|
+
validator_address: string
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}> {
|
|
101
|
+
const url = `${endpoint}/cosmos/staking/v1beta1/validators/${validator_addr}/delegations/${address}`
|
|
102
|
+
return get(url)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export async function getActiveValidators(endpoint: string) {
|
|
106
|
+
const url = `${endpoint}/cosmos/staking/v1beta1/validators?pagination.limit=300&status=BOND_STATUS_BONDED`
|
|
107
|
+
return get(url)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export async function getInactiveValidators(endpoint: string) {
|
|
111
|
+
const url = `${endpoint}/cosmos/staking/v1beta1/validators?pagination.limit=300&status=BOND_STATUS_UNBONDED`
|
|
112
|
+
return get(url)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// /ibc/apps/transfer/v1/denom_traces/{hash}
|
|
116
|
+
export async function getDenomTraces(endpoint: string, hash: string) : Promise<{
|
|
117
|
+
denom_trace: {
|
|
118
|
+
path: string;
|
|
119
|
+
base_denom: string;
|
|
120
|
+
};
|
|
121
|
+
}> {
|
|
122
|
+
const url = `${endpoint}/ibc/apps/transfer/v1/denom_traces/${hash}`
|
|
123
|
+
return get(url)
|
|
124
|
+
}
|
|
125
|
+
// /cosmos/tx/v1beta1/txs/{hash}
|
|
126
|
+
export async function getTxByHash(endpoint: string, hash: string) : Promise<{
|
|
127
|
+
tx_response: TxResponse;
|
|
128
|
+
}> {
|
|
129
|
+
const url = `${endpoint}/cosmos/tx/v1beta1/txs/${hash}`
|
|
130
|
+
return get(url)
|
|
131
|
+
}
|
|
132
|
+
// /cosmos/staking/v1beta1/params
|
|
133
|
+
export async function getStakingParam(endpoint: string) : Promise<{
|
|
134
|
+
params: {
|
|
135
|
+
unbonding_time: string;
|
|
136
|
+
max_validators: number;
|
|
137
|
+
max_entries: number;
|
|
138
|
+
historical_entries: number;
|
|
139
|
+
bond_denom: string;
|
|
140
|
+
};
|
|
141
|
+
}> {
|
|
142
|
+
const url = `${endpoint}/cosmos/staking/v1beta1/params`
|
|
143
|
+
return get(url)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export async function getOsmosisPools(endpoint: string) {
|
|
147
|
+
const url = `${endpoint}/osmosis/gamm/v1beta1/pools?pagination.limit=1000`
|
|
148
|
+
return get(url)
|
|
149
|
+
}
|
|
150
|
+
// https://lcd.osmosis.zone
|
|
151
|
+
// /osmosis/gamm/v1beta1/{pool_id}/estimate/swap_exact_amount_in
|
|
152
|
+
export async function estimateSwapAmountIn(endpoint: string, poolId: string, token: Coin) {
|
|
153
|
+
const url = `${endpoint}/osmosis/gamm/v1beta1/${poolId}/estimate/swap_exact_amount_in?token_in=${token.amount}${token.denom}`
|
|
154
|
+
return get(url)
|
|
155
155
|
}
|