From 5303a13055c800445fac9962b05b7852f47f6dfc Mon Sep 17 00:00:00 2001 From: mainnet-pat Date: Mon, 29 Jul 2024 07:09:25 +0000 Subject: [PATCH 01/24] Add featured tokens support Featured tokens will always be displayed, event if the wallet does not have them (zero balance) --- .editorconfig | 9 --------- .vscode/settings.json | 4 ++-- src/components/bchWallet.vue | 24 ++++++++++++----------- src/components/tokenItems/tokenItemFT.vue | 2 +- src/pages/WalletPage.vue | 7 +++++-- src/stores/store.ts | 6 +++++- src/utils/utils.ts | 9 ++++++++- 7 files changed, 34 insertions(+), 27 deletions(-) delete mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 9d08a1a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,9 +0,0 @@ -root = true - -[*] -charset = utf-8 -indent_style = space -indent_size = 2 -end_of_line = lf -insert_final_newline = true -trim_trailing_whitespace = true diff --git a/.vscode/settings.json b/.vscode/settings.json index 746cf57..8dcb2a8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,6 @@ { - "editor.bracketPairColorization.enabled": true, - "editor.guides.bracketPairs": true, + // "editor.bracketPairColorization.enabled": true, + // "editor.guides.bracketPairs": true, "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.codeActionsOnSave": [ diff --git a/src/components/bchWallet.vue b/src/components/bchWallet.vue index 514a855..cb96612 100644 --- a/src/components/bchWallet.vue +++ b/src/components/bchWallet.vue @@ -14,7 +14,7 @@ const { width } = useWindowSize(); const isMobile = computed(() => width.value < 480) - const nrTokenCategories = computed(() => store.tokenList?.length) + const nrTokenCategories = computed(() => store.tokenList?.filter(token => token.amount > 0n || token.nfts?.length > 0).length) const numberFormatter = new Intl.NumberFormat('en-US', {maximumFractionDigits: 8}); @@ -154,18 +154,20 @@ ? numberFormatter.format(store.balance[settingsStore.bchUnit] as number) + displayUnitLong : "" }} - - , Tokens: - - {{ nrTokenCategories != undefined ? nrTokenCategories + " different categories" : ""}} + + + , Tokens: + + {{ nrTokenCategories + " different categories"}} + +
+ Tokens: + + {{ nrTokenCategories + " different categories"}} + +
-
- Tokens: - - {{ nrTokenCategories != undefined ? nrTokenCategories + " different categories" : ""}} - -
BCH address: diff --git a/src/components/tokenItems/tokenItemFT.vue b/src/components/tokenItems/tokenItemFT.vue index 3f89a14..83c7eec 100644 --- a/src/components/tokenItems/tokenItemFT.vue +++ b/src/components/tokenItems/tokenItemFT.vue @@ -303,7 +303,7 @@
-
Amount: +
Amount: {{ numberFormatter.format(toAmountDecimals(tokenData?.amount)) }} {{ tokenMetaData?.token?.symbol }}
diff --git a/src/pages/WalletPage.vue b/src/pages/WalletPage.vue index 978c47f..c4eab12 100644 --- a/src/pages/WalletPage.vue +++ b/src/pages/WalletPage.vue @@ -13,7 +13,7 @@ import { convertElectrumTokenData } from "src/utils/utils" import type { TokenList } from "../interfaces/interfaces" import type { Web3WalletTypes } from '@walletconnect/web3wallet'; - import { useStore } from 'src/stores/store' + import { useStore, featuredTokens } from 'src/stores/store' import { useSettingsStore } from 'src/stores/settingsStore' import { useWalletconnectStore } from 'src/stores/walletconnectStore' import { useQuasar } from 'quasar' @@ -89,7 +89,10 @@ // get plannedTokenId if(!store.tokenList) return // should never happen console.time('importRegistries'); - await store.importRegistries(store.tokenList, false); + await Promise.all([ + store.importRegistries(store.tokenList, false), + store.importRegistries(featuredTokens.map((tokenId: string) => ({tokenId} as TokenDataFT | TokenDataNFT)), false), + ]); console.timeEnd('importRegistries'); console.time('planned tokenid'); await store.hasPreGenesis() diff --git a/src/stores/store.ts b/src/stores/store.ts index dbb9e53..7b40e48 100644 --- a/src/stores/store.ts +++ b/src/stores/store.ts @@ -15,6 +15,10 @@ BaseWallet.StorageProvider = IndexedDBProvider; const defaultBcmrIndexer = 'https://bcmr.paytaca.com/api'; const defaultBcmrIndexerChipnet = 'https://bcmr-chipnet.paytaca.com/api'; +export const featuredTokens = [ + "36546e4062a1cfd070a4a8d8ff9db18aae4ddf8d9ac9a4fa789314d108b49797" +]; + export const useStore = defineStore('store', () => { // Wallet State const wallet = ref(null as (Wallet | TestNetWallet | null)); @@ -31,7 +35,7 @@ export const useStore = defineStore('store', () => { async function updateTokenList(){ if(!wallet.value) return // should never happen const tokenUtxos = await wallet.value.getTokenUtxos(); - const fungibleTokensResult = getFungibleTokenBalances(tokenUtxos); + const fungibleTokensResult = getFungibleTokenBalances(tokenUtxos, featuredTokens); const nftsResult = getAllNftTokenBalances(tokenUtxos); if(!fungibleTokensResult || !nftsResult) return // should never happen const arrayTokens:TokenList = []; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index d509a41..036b363 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -15,7 +15,7 @@ export function getAllNftTokenBalances(tokenUtxos: UtxoI[]){ return result } -export function getFungibleTokenBalances(tokenUtxos: UtxoI[]){ +export function getFungibleTokenBalances(tokenUtxos: UtxoI[], featuredTokens: string[]){ const result:Record = {}; const fungiblesUtxos = tokenUtxos.filter((val) => val.token?.amount); for (const utxo of fungiblesUtxos) { @@ -25,6 +25,13 @@ export function getFungibleTokenBalances(tokenUtxos: UtxoI[]){ } result[utxo.token?.tokenId] += utxo.token.amount; } + + for (const tokenId of featuredTokens) { + if (!result[tokenId]) { + result[tokenId] = 0n; + } + } + return result } From 85b209d55cc51d91fa9eb1e1d83868c64a196518 Mon Sep 17 00:00:00 2001 From: mainnet-pat Date: Mon, 29 Jul 2024 07:24:52 +0000 Subject: [PATCH 02/24] Add settings toggles to show wallet connect and token creation dialogs, defaults to false --- src/components/settingsMenu.vue | 19 +++++++++++++++++++ src/pages/WalletPage.vue | 9 ++++++--- src/stores/settingsStore.ts | 19 ++++++++++++++++++- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/components/settingsMenu.vue b/src/components/settingsMenu.vue index ee722da..ddbc557 100644 --- a/src/components/settingsMenu.vue +++ b/src/components/settingsMenu.vue @@ -18,6 +18,8 @@ const selectedUnit = ref(settingsStore.bchUnit); const selectedExplorer = ref(store.explorerUrl); const selectedDarkMode = ref(settingsStore.darkMode); + const selectedWalletConnect = ref(settingsStore.walletConnect); + const selectedTokenCreation = ref(settingsStore.tokenCreation); const selectedTokenBurn = ref(settingsStore.tokenBurn); const selectedElectrumServer = ref(settingsStore.electrumServerMainnet); const selectedIpfsGateway = ref(settingsStore.ipfsGateway); @@ -57,8 +59,17 @@ localStorage.setItem("darkMode", selectedDarkMode.value? "true" : "false"); selectedDarkMode.value ? document.body.classList.add("dark") : document.body.classList.remove("dark") } + function changeWalletConnect(){ + settingsStore.walletConnect = selectedWalletConnect.value; + localStorage.setItem("walletConnect", selectedWalletConnect.value? "true" : "false"); + } + function changeTokenCreation(){ + settingsStore.tokenCreation = selectedTokenCreation.value; + localStorage.setItem("tokenCreation", selectedTokenCreation.value? "true" : "false"); + } function changeTokenBurn(){ settingsStore.tokenBurn = selectedTokenBurn.value; + localStorage.setItem("tokenBurn", selectedTokenBurn.value? "true" : "false"); } function toggleShowSeedphrase(){ displayeSeedphrase.value = !displayeSeedphrase.value; @@ -93,6 +104,14 @@
+
Enable WalletConnect + +
+ +
Enable token creation + +
+
Enable token-burn
diff --git a/src/pages/WalletPage.vue b/src/pages/WalletPage.vue index c4eab12..ae4f623 100644 --- a/src/pages/WalletPage.vue +++ b/src/pages/WalletPage.vue @@ -38,7 +38,10 @@ const signMessageRequestWC = ref(undefined as any); const dappMetadata = ref(undefined as any); const dappUriUrlParam = ref(undefined as undefined|string); - + + const walletConnect = ref(settingsStore.walletConnect); + const tokenCreation = ref(settingsStore.tokenCreation); + // check if wallet exists const mainnetWalletExists = await Wallet.namedExists(nameWallet); const testnetWalletExists = await TestNetWallet.namedExists(nameWallet); @@ -244,8 +247,8 @@