From 4fa85a8d6cb14b50fb2d25232b1e0e046c27dec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20C=2E=20Morency?= <1102868+fmorency@users.noreply.github.com> Date: Wed, 4 Dec 2024 12:42:49 -0500 Subject: [PATCH] fix: social wallet logo modal display (#113) --- components/react/authSignerModal.tsx | 3 ++- components/react/views/Connected.tsx | 10 ++++++++-- components/react/views/Connecting.tsx | 7 ++++++- components/react/views/Error.tsx | 3 ++- components/react/views/NotExist.tsx | 7 ++++++- components/react/views/WalletList.tsx | 15 ++++++++++++--- utils/logos.ts | 10 ++++++++++ 7 files changed, 46 insertions(+), 9 deletions(-) diff --git a/components/react/authSignerModal.tsx b/components/react/authSignerModal.tsx index ff78c7df..c11745c9 100644 --- a/components/react/authSignerModal.tsx +++ b/components/react/authSignerModal.tsx @@ -6,6 +6,7 @@ import { TxBody, AuthInfo } from '@liftedinit/manifestjs/dist/codegen/cosmos/tx/ import { decodePubkey } from '@cosmjs/proto-signing'; import { useWallet, useChain } from '@cosmos-kit/react'; import Image from 'next/image'; +import { getRealLogo } from '@/utils'; type DisplayDataToSignProps = { data: SignData; @@ -137,7 +138,7 @@ const SignModal = ({
- Wallet type logo + Wallet type logo

{walletName?.toString()} Direct Signer

- {name} + {name} {name} diff --git a/components/react/views/Connecting.tsx b/components/react/views/Connecting.tsx index 0827c594..ec452c6a 100644 --- a/components/react/views/Connecting.tsx +++ b/components/react/views/Connecting.tsx @@ -3,6 +3,7 @@ import { Dialog } from '@headlessui/react'; import { XMarkIcon } from '@heroicons/react/24/outline'; import { ChevronLeftIcon } from '@heroicons/react/20/solid'; +import { getRealLogo } from '@/utils'; export const Connecting = ({ onClose, @@ -41,7 +42,11 @@ export const Connecting = ({
- {name} + {name}

{title}

{subtitle}

diff --git a/components/react/views/Error.tsx b/components/react/views/Error.tsx index 161b3e8a..1805a0e8 100644 --- a/components/react/views/Error.tsx +++ b/components/react/views/Error.tsx @@ -4,6 +4,7 @@ import { Dialog } from '@headlessui/react'; import { XMarkIcon, ArrowPathIcon } from '@heroicons/react/24/outline'; import { ChevronLeftIcon } from '@heroicons/react/20/solid'; import Image from 'next/image'; +import { getRealLogo } from '@/utils'; export const Error = ({ currentWalletName, onClose, @@ -44,7 +45,7 @@ export const Error = ({
Wallet type logo
- {name} + {name}

Install {name}

To connect your {name} wallet, install the browser extension. diff --git a/components/react/views/WalletList.tsx b/components/react/views/WalletList.tsx index 530b25e9..41b23e7a 100644 --- a/components/react/views/WalletList.tsx +++ b/components/react/views/WalletList.tsx @@ -1,6 +1,7 @@ /* eslint-disable @next/next/no-img-element */ import { XMarkIcon } from '@heroicons/react/24/outline'; import { ChainWalletBase } from 'cosmos-kit'; +import { getRealLogo } from '@/utils'; export const WalletList = ({ onClose, @@ -48,7 +49,11 @@ export const WalletList = ({ onClick={() => onWalletClicked(name)} className="flex items-center w-full p-3 rounded-lg dark:bg-[#ffffff0c] bg-[#f0f0ff5c] dark:hover:bg-[#0000004c] hover:bg-[#a8a8a84c] transition" > - {prettyName} + {prettyName} {prettyName} ))} @@ -66,7 +71,7 @@ export const WalletList = ({ className="flex items-center justify-center p-4 dark:bg-[#ffffff0c] bg-[#f0f0ff5c] dark:hover:bg-[#0000004c] hover:bg-[#a8a8a84c] rounded-lg transition" > {prettyName} @@ -84,7 +89,11 @@ export const WalletList = ({ onClick={() => onWalletClicked(name)} className="flex items-center w-full p-3 rounded-lg dark:bg-[#ffffff0c] bg-[#f0f0ff5c] dark:hover:bg-[#0000004c] hover:bg-[#a8a8a84c] transition" > - {prettyName} + {prettyName} {prettyName === 'Twitter' ? 'X' : prettyName} ))} diff --git a/utils/logos.ts b/utils/logos.ts index 059d3759..94c49f54 100644 --- a/utils/logos.ts +++ b/utils/logos.ts @@ -40,6 +40,16 @@ export const convertChainName = (chainName: string) => { } }; +export const getRealLogo = (logo: string) => { + const isDarkMode = document.documentElement.classList.contains('dark'); + const localAndHasExtension = /^\/(?!.*\.[0-9a-z]+$)/i.test(logo); + return localAndHasExtension + ? isDarkMode + ? logo?.toString() + '_light.svg' + : logo?.toString() + '_dark.svg' + : logo; +}; + export const isUrlValid = async (url: string) => { const res = await fetch(url, { method: 'HEAD',