From dfe0a27f77cf713eb10cb2fbfe69455de7732c86 Mon Sep 17 00:00:00 2001 From: Noah Saso Date: Wed, 11 Oct 2023 16:36:14 -0700 Subject: [PATCH] Use Cosmos Kit with Keplr Extension support. --- components/AirdropUpload.tsx | 8 +- components/BadgeAirdropListUpload.tsx | 8 +- components/Sidebar.tsx | 4 +- components/WalletLoader.tsx | 51 +- components/WalletProvider.tsx | 31 + components/WhitelistFlexUpload.tsx | 8 +- components/WhitelistUpload.tsx | 8 +- components/badges/actions/Action.tsx | 16 +- components/badges/creation/BadgeDetails.tsx | 14 +- components/badges/queries/Queries.tsx | 3 - components/collections/actions/Action.tsx | 20 +- .../creation/BaseMinterDetails.tsx | 28 +- .../collections/creation/MintingDetails.tsx | 2 +- .../collections/creation/RoyaltyDetails.tsx | 2 +- .../collections/creation/WhitelistDetails.tsx | 2 +- components/collections/queries/Queries.tsx | 2 +- components/forms/AddressList.tsx | 8 +- components/forms/FlexMemberAttributes.tsx | 8 +- components/openEdition/MintingDetails.tsx | 2 +- .../OnChainMetadataInputDetails.tsx | 2 - .../openEdition/OpenEditionMinterCreator.tsx | 16 +- components/openEdition/RoyaltyDetails.tsx | 2 +- config/index.ts | 1 - config/keplr.ts | 76 - contexts/collection.ts | 2 +- contexts/contracts.tsx | 5 +- contexts/globalSettings.ts | 2 +- contexts/log.ts | 2 +- contexts/sidebar.ts | 2 +- contexts/wallet.tsx | 289 ---- contracts/badgeHub/useContract.ts | 28 +- contracts/baseFactory/useContract.ts | 18 +- contracts/baseMinter/useContract.ts | 28 +- contracts/openEditionFactory/useContract.ts | 18 +- contracts/openEditionMinter/useContract.ts | 28 +- contracts/royaltyRegistry/useContract.ts | 23 +- contracts/sg721/useContract.ts | 26 +- contracts/splits/useContract.ts | 23 +- contracts/vendingFactory/useContract.ts | 18 +- contracts/vendingMinter/useContract.ts | 28 +- contracts/whitelist/useContract.ts | 18 +- env.d.ts | 4 +- package.json | 8 +- pages/_app.tsx | 2 +- pages/badges/actions.tsx | 9 +- pages/badges/create.tsx | 12 +- pages/badges/myBadges.tsx | 6 +- pages/collections/actions.tsx | 16 +- pages/collections/create.tsx | 56 +- pages/collections/myCollections.tsx | 6 +- pages/contracts/badgeHub/execute.tsx | 13 +- pages/contracts/badgeHub/instantiate.tsx | 2 +- pages/contracts/badgeHub/migrate.tsx | 4 +- pages/contracts/badgeHub/query.tsx | 6 +- pages/contracts/baseMinter/execute.tsx | 6 +- pages/contracts/baseMinter/instantiate.tsx | 6 +- pages/contracts/baseMinter/migrate.tsx | 4 +- pages/contracts/baseMinter/query.tsx | 6 +- pages/contracts/openEditionMinter/execute.tsx | 15 +- pages/contracts/openEditionMinter/migrate.tsx | 4 +- pages/contracts/openEditionMinter/query.tsx | 6 +- pages/contracts/royaltyRegistry/execute.tsx | 4 +- pages/contracts/royaltyRegistry/query.tsx | 6 +- pages/contracts/sg721/execute.tsx | 4 +- pages/contracts/sg721/migrate.tsx | 4 +- pages/contracts/sg721/query.tsx | 6 +- pages/contracts/splits/execute.tsx | 4 +- pages/contracts/splits/instantiate.tsx | 2 +- pages/contracts/splits/migrate.tsx | 4 +- pages/contracts/splits/query.tsx | 6 +- pages/contracts/vendingMinter/execute.tsx | 15 +- pages/contracts/vendingMinter/instantiate.tsx | 4 +- pages/contracts/vendingMinter/migrate.tsx | 4 +- pages/contracts/vendingMinter/query.tsx | 6 +- pages/contracts/whitelist/execute.tsx | 11 +- pages/contracts/whitelist/instantiate.tsx | 2 +- pages/contracts/whitelist/query.tsx | 6 +- pages/revoke.tsx | 11 +- services/keplr.ts | 4 - utils/getSignatureVerificationData.ts | 21 - utils/isValidFile.ts | 6 +- utils/resolveAddress.ts | 10 +- utils/sort.ts | 10 +- utils/wallet.ts | 18 + yarn.lock | 1541 +++++++++++++---- 85 files changed, 1776 insertions(+), 1004 deletions(-) create mode 100644 components/WalletProvider.tsx delete mode 100644 config/keplr.ts delete mode 100644 contexts/wallet.tsx delete mode 100644 services/keplr.ts delete mode 100644 utils/getSignatureVerificationData.ts create mode 100644 utils/wallet.ts diff --git a/components/AirdropUpload.tsx b/components/AirdropUpload.tsx index 81711de..1e3c330 100644 --- a/components/AirdropUpload.tsx +++ b/components/AirdropUpload.tsx @@ -1,6 +1,5 @@ import { toUtf8 } from '@cosmjs/encoding' import clsx from 'clsx' -import { useWallet } from 'contexts/wallet' import React, { useState } from 'react' import { toast } from 'react-hot-toast' import { SG721_NAME_ADDRESS } from 'utils/constants' @@ -8,6 +7,7 @@ import { csvToArray } from 'utils/csvToArray' import type { AirdropAllocation } from 'utils/isValidAccountsFile' import { isValidAccountsFile } from 'utils/isValidAccountsFile' import { isValidAddress } from 'utils/isValidAddress' +import { useWallet } from 'utils/wallet' interface AirdropUploadProps { onChange: (data: AirdropAllocation[]) => void @@ -22,8 +22,10 @@ export const AirdropUpload = ({ onChange }: AirdropUploadProps) => { await new Promise((resolve) => { let i = 0 allocationData.map(async (data) => { - if (!wallet.client) throw new Error('Wallet not connected') - await wallet.client + if (!wallet.isWalletConnected) throw new Error('Wallet not connected') + await ( + await wallet.getCosmWasmClient() + ) .queryContractRaw( SG721_NAME_ADDRESS, toUtf8( diff --git a/components/BadgeAirdropListUpload.tsx b/components/BadgeAirdropListUpload.tsx index 4a035de..80233c0 100644 --- a/components/BadgeAirdropListUpload.tsx +++ b/components/BadgeAirdropListUpload.tsx @@ -5,8 +5,8 @@ import { toUtf8 } from '@cosmjs/encoding' import clsx from 'clsx' import React, { useState } from 'react' import { toast } from 'react-hot-toast' +import { useWallet } from 'utils/wallet' -import { useWallet } from '../contexts/wallet' import { SG721_NAME_ADDRESS } from '../utils/constants' import { isValidAddress } from '../utils/isValidAddress' @@ -22,8 +22,10 @@ export const BadgeAirdropListUpload = ({ onChange }: BadgeAirdropListUploadProps await new Promise((resolve) => { let i = 0 names.map(async (name) => { - if (!wallet.client) throw new Error('Wallet not connected') - await wallet.client + if (!wallet.isWalletConnected) throw new Error('Wallet not connected') + await ( + await wallet.getCosmWasmClient() + ) .queryContractRaw( SG721_NAME_ADDRESS, toUtf8( diff --git a/components/Sidebar.tsx b/components/Sidebar.tsx index f5e228e..7f6af6f 100644 --- a/components/Sidebar.tsx +++ b/components/Sidebar.tsx @@ -6,13 +6,13 @@ import { Anchor } from 'components/Anchor' import type { Timezone } from 'contexts/globalSettings' import { setTimezone } from 'contexts/globalSettings' import { setLogItemList, useLogStore } from 'contexts/log' -import { useWallet } from 'contexts/wallet' import Link from 'next/link' import { useRouter } from 'next/router' import { useEffect } from 'react' import { FaCog } from 'react-icons/fa' // import BrandText from 'public/brand/brand-text.svg' import { footerLinks, socialsLinks } from 'utils/links' +import { useWallet } from 'utils/wallet' import { BADGE_HUB_ADDRESS, BASE_FACTORY_ADDRESS, NETWORK, OPEN_EDITION_FACTORY_ADDRESS } from '../utils/constants' import { Conditional } from './Conditional' @@ -268,7 +268,7 @@ export const Sidebar = () => { {/* Stargaze network status */} -
Network: {wallet.network}
+
Network: {wallet.chain.pretty_name}
{/* footer reference links */}