feat: add side

This commit is contained in:
showlizi 2024-06-14 17:26:14 +08:00
parent 6756c41676
commit d0c4278f84
6 changed files with 211 additions and 4 deletions

81
chains/mainnet/side.json Normal file
View File

@ -0,0 +1,81 @@
{
"chain_name": "SIDE-Testnet",
"api": [],
"rpc": [
"https://testnet-rpc.side.one",
"https://testnet-rpc2.side.one"
],
"faucet": "https://testnet.side.one/faucet",
"snapshot_provider": "",
"sdk_version": "0.45.6",
"coin_type": "118",
"min_tx_fee": "800",
"addr_prefix": "side",
"logo": "/logos/side.png",
"theme_color": "#161723",
"assets": [
{
"base": "uside",
"symbol": "SIDE",
"name": "Side protocol",
"exponent": "6",
"coingecko_id": "usd-coin",
"logo": "side-SIDE",
"precision": 6
},
{
"base": "abtct",
"symbol": "BTCT",
"name": "Bitcoin Token",
"exponent": "8",
"coingecko_id": "bitcoin",
"logo": "",
"precision": 8
},
{
"base": "uusdc",
"symbol": "USDC",
"name": "USD Coin",
"exponent": "6",
"coingecko_id": "usd-coin",
"logo": "side-USDC",
"precision": 6
},
{
"base": "uusdt",
"symbol": "USDT",
"name": "Tether USD",
"exponent": "6",
"coingecko_id": "usd-coin",
"logo": "data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllciAxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzMzkuNDMgMjk1LjI3Ij48dGl0bGU+dGV0aGVyLXVzZHQtbG9nbzwvdGl0bGU+PHBhdGggZD0iTTYyLjE1LDEuNDVsLTYxLjg5LDEzMGEyLjUyLDIuNTIsMCwwLDAsLjU0LDIuOTRMMTY3Ljk1LDI5NC41NmEyLjU1LDIuNTUsMCwwLDAsMy41MywwTDMzOC42MywxMzQuNGEyLjUyLDIuNTIsMCwwLDAsLjU0LTIuOTRsLTYxLjg5LTEzMEEyLjUsMi41LDAsMCwwLDI3NSwwSDY0LjQ1YTIuNSwyLjUsMCwwLDAtMi4zLDEuNDVoMFoiIHN0eWxlPSJmaWxsOiM1MGFmOTU7ZmlsbC1ydWxlOmV2ZW5vZGQiLz48cGF0aCBkPSJNMTkxLjE5LDE0NC44djBjLTEuMi4wOS03LjQsMC40Ni0yMS4yMywwLjQ2LTExLDAtMTguODEtLjMzLTIxLjU1LTAuNDZ2MGMtNDIuNTEtMS44Ny03NC4yNC05LjI3LTc0LjI0LTE4LjEzczMxLjczLTE2LjI1LDc0LjI0LTE4LjE1djI4LjkxYzIuNzgsMC4yLDEwLjc0LjY3LDIxLjc0LDAuNjcsMTMuMiwwLDE5LjgxLS41NSwyMS0wLjY2di0yOC45YzQyLjQyLDEuODksNzQuMDgsOS4yOSw3NC4wOCwxOC4xM3MtMzEuNjUsMTYuMjQtNzQuMDgsMTguMTJoMFptMC0zOS4yNVY3OS42OGg1OS4yVjQwLjIzSDg5LjIxVjc5LjY4SDE0OC40djI1Ljg2Yy00OC4xMSwyLjIxLTg0LjI5LDExLjc0LTg0LjI5LDIzLjE2czM2LjE4LDIwLjk0LDg0LjI5LDIzLjE2djgyLjloNDIuNzhWMTUxLjgzYzQ4LTIuMjEsODQuMTItMTEuNzMsODQuMTItMjMuMTRzLTM2LjA5LTIwLjkzLTg0LjEyLTIzLjE1aDBabTAsMGgwWiIgc3R5bGU9ImZpbGw6I2ZmZjtmaWxsLXJ1bGU6ZXZlbm9kZCIvPjwvc3ZnPg==",
"precision": 6
},
{
"base": "uwbtc",
"coingecko_id": "bitcoin",
"exponent": "8",
"logo": "",
"name": "Wrapped BTC",
"precision": 8,
"symbol": "wBTC"
},
{
"base": "ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349",
"symbol": "USDC",
"name": "USD Coin (ibc)",
"exponent": "6",
"coingecko_id": "usd-coin",
"logo": "side-USDC",
"precision": 6
},
{
"base": "ibc/4BDF2D63B8FFE3454AF30E9BC10D2D7979BD3A938D989889ABC94FC5B86F1E2D",
"symbol": "aUSDC",
"name": "aUSDC.axl (ibc)",
"exponent": "6",
"coingecko_id": "usd-coin",
"logo": "https://testnet.satellite.money/assets/tokens/uausdc.logo.svg",
"precision": 6
}
]
}

View File

@ -1,8 +1,10 @@
<script setup lang="ts">
import { useRoute } from 'vue-router'
import { useBaseStore, useBlockchain, useWalletStore } from '@/stores';
import { Icon } from '@iconify/vue';
import { ref, computed } from 'vue';
const route = useRoute();
const walletStore = useWalletStore();
const chainStore = useBlockchain();
const baseStore = useBaseStore();
@ -32,6 +34,22 @@ const tipMsg = computed(() => {
? { class: 'error', msg: 'Copy Error!' }
: { class: 'success', msg: 'Copy Success!' };
});
// console.log(`route: `, route);
// console.log(`baseStore: `, baseStore);
// console.log(`baseStore: currentChainId`, baseStore.currentChainId);
// console.log(`baseStore: defaultHDPath`, chainStore?.value?.defaultHDPath);
// console.log(`baseStore: `, walletStateChange);
// console.log(`baseStore: `, walletStore.suggestChain());
let chainId = baseStore?.value?.currentChainId;
let params = '';
if (route.path === '/SIDE-Testnet') {
chainId = 'S2-testnet-2';
params = JSON.stringify({
wallet: ['okex', 'unisat']
})
}
</script>
<template>
@ -83,7 +101,7 @@ const tipMsg = computed(() => {
</div>
</div>
<Teleport to="body">
<ping-connect-wallet :chain-id="baseStore.currentChainId" :hd-path="chainStore.defaultHDPath"
<ping-connect-wallet :params="params" :chain-id="chainId" :hd-path="chainStore.defaultHDPath"
:addr-prefix="chainStore.current?.bech32Prefix || 'cosmos'" @connect="walletStateChange"
@keplr-config="walletStore.suggestChain()" />
</Teleport>

View File

@ -13,6 +13,7 @@ const selected = ref({} as ChainConfig)
onMounted(() => {
const chainStore = useBlockchain()
selected.value = chainStore.current || Object.values(dashboard.chains)[0]
debugger;
initParamsForKeplr()
})
async function initParamsForKeplr() {

View File

@ -0,0 +1,104 @@
<script setup lang="ts">
import { ref } from 'vue';
import { useDashboard, type ChainConfig, useBlockchain } from '@/stores';
import { CosmosRestClient } from '@/libs/client';
import { onMounted } from 'vue';
import AdBanner from '@/components/ad/AdBanner.vue';
const error = ref("")
const conf = ref("")
const dashboard = useDashboard()
const selected = ref({} as ChainConfig)
onMounted(() => {
const chainStore = useBlockchain()
selected.value = chainStore.current || Object.values(dashboard.chains)[0];
})
async function initParamsForKeplr() {
const chain = selected.value
if(!chain.endpoints?.rest?.at(0)) throw new Error("Endpoint does not set");
const client = CosmosRestClient.newDefault(chain.endpoints.rest?.at(0)?.address || "")
const b = await client.getBaseBlockLatest()
const chainid = b.block.header.chain_id
const gasPriceStep = chain.keplrPriceStep || {
low: 0.01,
average: 0.025,
high: 0.03,
}
const coinDecimals = chain.assets[0].denom_units.find(x => x.denom === chain.assets[0].symbol.toLowerCase())?.exponent || 6
conf.value = JSON.stringify({
chainId: chainid,
chainName: chain.chainName,
rpc: chain.endpoints?.rpc?.at(0)?.address,
rest: chain.endpoints?.rest?.at(0)?.address,
bip44: {
coinType: Number(chain.coinType),
},
coinType: Number(chain.coinType),
bech32Config: {
bech32PrefixAccAddr: chain.bech32Prefix,
bech32PrefixAccPub: `${chain.bech32Prefix}pub`,
bech32PrefixValAddr: `${chain.bech32Prefix}valoper`,
bech32PrefixValPub: `${chain.bech32Prefix}valoperpub`,
bech32PrefixConsAddr: `${chain.bech32Prefix}valcons`,
bech32PrefixConsPub: `${chain.bech32Prefix}valconspub`,
},
currencies: [
{
coinDenom: chain.assets[0].symbol,
coinMinimalDenom: chain.assets[0].base,
coinDecimals,
coinGeckoId: chain.assets[0].coingecko_id || 'unknown',
},
],
feeCurrencies: [
{
coinDenom: chain.assets[0].symbol,
coinMinimalDenom: chain.assets[0].base,
coinDecimals,
coinGeckoId: chain.assets[0].coingecko_id || 'unknown',
gasPriceStep,
},
],
gasPriceStep,
stakeCurrency: {
coinDenom: chain.assets[0].symbol,
coinMinimalDenom: chain.assets[0].base,
coinDecimals,
coinGeckoId: chain.assets[0].coingecko_id || 'unknown',
},
features: chain.keplrFeatures || [],
}, null, '\t')
}
function suggest() {
// @ts-ignore
if (window.unisat) {
// @ts-ignore
window.unisat.experimentalSuggestChain(JSON.parse(conf.value)).catch(e => {
error.value = e
})
}
}
</script>
<template>
<div class="bg-base-100 p-4 rounded text-center">
<AdBanner id="keplr-banner-ad" unit="banner" width="970px" height="90px" />
<div class="flex">
<select v-model="selected" class="select select-bordered mx-5" @change="initParamsForKeplr">
<option v-for="c in dashboard.chains" :value="c">
{{ c.chainName }}
</option>
</select>
<button class="btn !bg-yes !border-yes text-white px-10" @click="suggest">Add {{ selected.chainName }} TO Unisat Wallet</button>
</div>
<div class="text-main mt-5">
<textarea v-model="conf" class="textarea textarea-bordered w-full" rows="15"></textarea>
</div>
<div class="mt-4 mb-4">
If the chain is not offically support on Keplr, you can submit these parameters to enable Keplr.
</div>
</div>
</template>

View File

@ -14,7 +14,7 @@ const router = createRouter({
router.beforeEach((to) => {
const { chain } = to.params
if(chain){
const blockchain = useBlockchain()
const blockchain= useBlockchain()
if(chain !== blockchain.chainName) {
blockchain.setCurrent(chain.toString())
}

View File

@ -128,8 +128,11 @@ export const useWalletStore = defineStore('walletStore', {
if(value) this.wallet = value
},
suggestChain() {
// const router = useRouter()
router.push({path: '/wallet/keplr'})
if (window.location.pathname === '/SIDE-Testnet') {
router.push({path: '/wallet/unisat'})
} else {
router.push({path: '/wallet/keplr'})
}
}
},
});