From e557ad04011c812704f59361a5b770ef67d61f75 Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Sat, 27 May 2023 22:09:22 +0800 Subject: [PATCH 1/5] add ledger logo --- public/logos/ledger.jpeg | Bin 0 -> 2660 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 public/logos/ledger.jpeg diff --git a/public/logos/ledger.jpeg b/public/logos/ledger.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..46949821264d114ca18f3ba59017014a1dbe0f3f GIT binary patch literal 2660 zcmbuAdpy+X9><@#8OHri$xKVcQMyc$8naeRNK-Ajv{t&%xFp79%4ilDWtAh99n_Gb za;XVfYFUO6yN*>ZWie)^rAUoiCT8Y$e$IOBdA-g#f9yHu`#isYp5OQRJ)igUz5Jk; z&?wOHboX!v2m}Hgfd_z;V5jRrHy0o3K_^1k@eSdpPlOQ?HgDWSSRYTPoeCp(cv1+S z``svn1jkJ_c7&MtkVsnG83Kv0V-pVg6}SQv61hBKL&FoJiou}K7#tR>qN;(@&``&z zt7~fM>1b-{YN@O180qNh8yFfIYG@mq7#W!885kNYe*}So_nt^Mrn;uVe{Il@ zKv#8{2!+rENL>U<7Xh^bJOBs`jJiy_VhALxQ3b22hEs7=pP8deimb}B_*d=)#3|Yv*E!WspZzAv8ie}BV!ZORqL#**W1_fNg z+~MT9+s&P_$HVhWAKycM{sDoLLt^wl+mfPc z@I_8BuUXAv>p`jE(byiGktI>IZh9H*A7p)m`i;gfh}nrjsXk4BfWFe0 z@nu_gXajxn?D178H37St)pAgg!zoWp1*e^_UH)4eUXK|FfzcF&t)n+`b?-PC7%GE4;G1q>?vi?Q93*GKmulqD1x>Q7Yq;>2=H;^s4$hacS?X61F z-lKiQAa{F*k+F>uM?zZXLqclVUtLrly(}r}BCOmjzCbAT=jsK!hDf_V_u#}$a_k?3 zUNATJZ(V;rJH+lg2r&A4FXnu@84;^31Qtn?Rb;i?p_%+624KI%yoFMALF_dtL^5~(GREOjU(Bl?E@!-a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 ++ src/modules/[chain]/index.vue | 8 +++++--- 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 public/logos/ledger.webp diff --git a/public/logos/ledger.webp b/public/logos/ledger.webp new file mode 100644 index 0000000000000000000000000000000000000000..9c733a10ec0abd9ecd36b486d862a1c023725a90 GIT binary patch literal 1002 zcmWIYbaQ*e%)k)t>J$(bU=hK^z`(!(#HSfS2q>Zu2bA65%rKWx>kQ)=M!TtA^F39R z7EbbCBH_a6@@0F$t`)sM&;K<3_36m>AKeMQd;(YRurI7$%H17$*hjAQ-4s3Da9)Ed z@m&Esw#Jwod=dB3>Cx4K%LJ5MW#w|8`skmI7GL(cwi&kEm5h%M z09~Qov`Ofu@^!U`({}}Ib-Z^!`Co(UVf~W1J9fVVInMZN@1ZWBYM?z)HElQc$(e50 zhj9N+QQ3da2oI@oFGup#xwHa)r|(|kVyi*cT@9RA0CZ4H)HF3V#y08F%AJxpa5B-0at+G6n(r2Y~rfP^)ntk z00v|qKMUA3q2B-d8Gu2#;gNLTX}){;;%DBO6z+A-i;UBs`J&B5n(Jqq&3jo9{vtJ^5OL|x z!0_*X;T2%oVf}yOsEJ*!&AY^#*$WmHPhDp!bj?5hwZf4@0l z8Rx;MUq|k3xwLxMWbLkx%huk>T)KU;c|)-3>XiJ;1`k9Oe~C2atyJl_dYNI#&!}H# z*eWI*HF?t2{E=@X|Ezb8OU`~=zRO1T&w`rIP4T7{Iy2p;JhE}CWYBj$vtV0r!TyiG z6K`9IpZPKY=qNC7jqr4f1F}3lwZM6gks-64g@F+$A_Y+ZWVcOXXD|Ztbf6-R!OotZ wK(?Wtsh**(k+F-elbgSfnYpQHprdO + +
 
diff --git a/src/modules/[chain]/index.vue b/src/modules/[chain]/index.vue index ff35ed95..b5deedb9 100644 --- a/src/modules/[chain]/index.vue +++ b/src/modules/[chain]/index.vue @@ -365,19 +365,21 @@ const color = computed(() => { -
+
Application Versions
+
-
+
Node Information
- + +
From d08e6bb237804616a8588915c2909f8e8a0af7fc Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Sun, 28 May 2023 11:15:29 +0800 Subject: [PATCH 3/5] improve account page --- src/modules/wallet/accounts.vue | 148 +++++++++++++++++++++++--------- src/modules/wallet/utils.ts | 60 +++++++------ 2 files changed, 141 insertions(+), 67 deletions(-) diff --git a/src/modules/wallet/accounts.vue b/src/modules/wallet/accounts.vue index 9b777372..92adad83 100644 --- a/src/modules/wallet/accounts.vue +++ b/src/modules/wallet/accounts.vue @@ -2,15 +2,18 @@ import { CosmosRestClient } from '@/libs/client'; import { useDashboard, useFormatter } from '@/stores'; import type { Coin, Delegation } from '@/types'; -import { fromBech32, toBase64, toBech32 } from '@cosmjs/encoding'; +import { fromBech32, toBase64, toBech32, toHex } from '@cosmjs/encoding'; import { Icon } from '@iconify/vue'; import { computed } from 'vue'; import { ref } from 'vue'; -import { scanLocalKeys, type AccountEntry, scanCompatibleAccounts } from './utils'; +import { scanLocalKeys, type AccountEntry, scanCompatibleAccounts, type LocalKey } from './utils'; const dashboard = useDashboard() const format = useFormatter() const editable = ref(false) // to edit addresses +const source = ref('wallet'); // values: wallet, imported, address +const sourceAddress = ref('') // +const selectedSource = ref({} as LocalKey) // function toggleEdit() { editable.value = !editable.value } @@ -19,10 +22,12 @@ const conf = ref(JSON.parse(localStorage.getItem("imported-addresses") || "{}") const balances = ref({} as Record) const delegations = ref({} as Record) +// auto import current connected wallet. scanLocalKeys().forEach(wallet => { const { data } = fromBech32(wallet.cosmosAddress) const walletKey = toBase64(data) let imported = conf.value[walletKey] + console.log('imported:', imported) // save the default address to local storage if (!imported) { imported = [] @@ -81,14 +86,52 @@ const addresses = computed(() => { return accounts.value.map(x => (x.address)) }) +const sourceOptions = computed(() => { + // scan all connected wallet + const keys = scanLocalKeys() + // all existed keys + Object.values(conf.value).forEach(x => { + const [first] = x + if (first) { + const { data } = fromBech32(first.address) + const hex = toHex(data) + if (keys.findIndex(k => toHex(fromBech32(k.cosmosAddress).data) === hex) === -1) { + keys.push({ + cosmosAddress: first.address, + hdPath: `m/44/${first.coinType}/0'/0/0` + }) + } + } + }) + // address + if (sourceAddress.value) { + const { prefix, data } = fromBech32(sourceAddress.value) + const chain = Object.values(dashboard.chains).find(x => x.bech32Prefix === prefix) + if (chain) { + keys.push({ + cosmosAddress: sourceAddress.value, + hdPath: `m/44/${chain.coinType}/0'/0/0` + }) + } + } + if (!selectedSource.value.cosmosAddress && keys.length > 0) { + selectedSource.value = keys[0] + } + return keys +}) + const availableAccount = computed(() => { - return scanCompatibleAccounts().filter(x => !addresses.value.includes(x.address)) + if (selectedSource.value.cosmosAddress) { + return scanCompatibleAccounts([selectedSource.value]).filter(x => !addresses.value.includes(x.address)) + } + return [] }) function removeAddress(addr: string) { const newConf = {} as Record Object.keys(conf.value).forEach(key => { - newConf[key] = conf.value[key].filter(x => x.address !== addr) + const acc = conf.value[key].filter(x => x.address !== addr) + if (acc.length > 0) newConf[key] = acc }) conf.value = newConf localStorage.setItem("imported-addresses", JSON.stringify(conf.value)) @@ -96,23 +139,36 @@ function removeAddress(addr: string) { async function addAddress(acc: AccountEntry) { console.log('add', acc) - const {data} = fromBech32(acc.address) + const { data } = fromBech32(acc.address) const key = toBase64(data) - if(conf.value[key]) { + if (conf.value[key]) { + // existed + if (conf.value[key].findIndex(x => x.address === acc.address) > -1) { + return + } conf.value[key].push(acc) } else { conf.value[key] = [acc] } - if(acc.endpoint) { + // also add chain to favorite + if(!dashboard?.favoriteMap?.[acc.chainName]) { + dashboard.favoriteMap[acc.chainName] = true + window.localStorage.setItem( + 'favoriteMap', + JSON.stringify(dashboard.favoriteMap) + ); + } + + if (acc.endpoint) { const client = CosmosRestClient.newDefault(acc.endpoint) client.getBankBalances(acc.address).then(res => { balances.value[acc.address] = res.balances.filter(x => x.denom.length < 10) }) client.getStakingDelegations(acc.address).then(res => { delegations.value[acc.address] = res.delegation_responses - }) + }) } localStorage.setItem("imported-addresses", JSON.stringify(conf.value)) @@ -169,9 +225,10 @@ async function addAddress(acc: AccountEntry) {
- + +
- + @@ -186,11 +243,11 @@ async function addAddress(acc: AccountEntry) { -
Account +
-
+
@@ -232,45 +289,56 @@ async function addAddress(acc: AccountEntry) {
diff --git a/src/modules/wallet/utils.ts b/src/modules/wallet/utils.ts index f096d9c3..acdb5ae7 100644 --- a/src/modules/wallet/utils.ts +++ b/src/modules/wallet/utils.ts @@ -10,39 +10,45 @@ export interface AccountEntry { endpoint?: string, delegation?: Coin, balances?: Coin[], + compatiable?: boolean, +} + +export interface LocalKey { + cosmosAddress: string, hdPath: string } export function scanLocalKeys() { - const connected = [] as {cosmosAddress: string, hdPath: string}[] - for (let i = 0; i < localStorage.length; i++) { - const key = localStorage.key(i) - if (key?.startsWith("m/44")) { - const wallet = JSON.parse(localStorage.getItem(key) || "") - if (wallet) { - connected.push(wallet) - } + const connected = [] as LocalKey[] + for (let i = 0; i < localStorage.length; i++) { + const key = localStorage.key(i) + if (key?.startsWith("m/44")) { + const wallet = JSON.parse(localStorage.getItem(key) || "") + if (wallet) { + connected.push(wallet) } } - return connected } + return connected +} - -export function scanCompatibleAccounts() { - const dashboard = useDashboard() - const available = [] as AccountEntry[] - scanLocalKeys().forEach(wallet => { - Object.values(dashboard.chains).forEach(chain => { - if (wallet.hdPath.indexOf(chain.coinType) === 6) { - const { data } = fromBech32(wallet.cosmosAddress) - available.push({ - chainName: chain.chainName, - logo: chain.logo, - address: toBech32(chain.bech32Prefix, data), - coinType: chain.coinType, - endpoint: chain.endpoints.rest?.at(0)?.address - }) - } + +export function scanCompatibleAccounts(keys: LocalKey[]) { + const dashboard = useDashboard() + const available = [] as AccountEntry[] + console.log("from keys:", keys) + keys.forEach(wallet => { + Object.values(dashboard.chains).forEach(chain => { + const { data } = fromBech32(wallet.cosmosAddress) + available.push({ + chainName: chain.chainName, + logo: chain.logo, + address: toBech32(chain.bech32Prefix, data), + coinType: chain.coinType, + compatiable: wallet.hdPath.indexOf(chain.coinType) > 0, + endpoint: chain.endpoints.rest?.at(0)?.address }) }) - return available - } \ No newline at end of file + }) + console.log(available) + return available +} \ No newline at end of file From 568dc508ad5cbd4f8281a72a2bfa26fe6648ca68 Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Sun, 28 May 2023 11:15:49 +0800 Subject: [PATCH 4/5] account page --- src/stores/useWalletStore.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stores/useWalletStore.ts b/src/stores/useWalletStore.ts index eebea3a1..17814896 100644 --- a/src/stores/useWalletStore.ts +++ b/src/stores/useWalletStore.ts @@ -17,7 +17,7 @@ export const useWalletStore = defineStore('walletStore', { delegations: [] as Delegation[], unbonding: [] as UnbondingResponses[], rewards: {} as DelegatorRewards, - walletIsConnected: {} as WalletConnected | null + walletIsConnected: {} as WalletConnected }; }, getters: { From 3d41046b1cc765c1e622a035bc98bd7a0dac738f Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Sun, 28 May 2023 13:24:59 +0800 Subject: [PATCH 5/5] improve wallet accounts --- src/layouts/components/NavBarWallet.vue | 4 +- src/modules/wallet/accounts.vue | 69 +++++++++---------------- src/modules/wallet/utils.ts | 3 -- 3 files changed, 27 insertions(+), 49 deletions(-) diff --git a/src/layouts/components/NavBarWallet.vue b/src/layouts/components/NavBarWallet.vue index 712555d8..baa01899 100644 --- a/src/layouts/components/NavBarWallet.vue +++ b/src/layouts/components/NavBarWallet.vue @@ -37,7 +37,7 @@ const tipMsg = computed(() => {