Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix WalletConnect modals in mobile wallet redesign #1071

Merged
merged 2 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions apps/desktop-wallet/src/features/modals/modalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You should have received a copy of the GNU Lesser General Public License
along with the library. If not, see <http://www.gnu.org/licenses/>.
*/

import { AddressHash } from '@alephium/shared'
import { AddressHash, WalletConnectSessionProposalModalProps } from '@alephium/shared'

import { CallContractSendModalProps } from '@/features/send/sendModals/callContract/CallContractSendModal'
import { DeployContractSendModalProps } from '@/features/send/sendModals/deployContract/DeployContractSendModal'
Expand All @@ -26,7 +26,6 @@ import { WalletUnlockModalProps } from '@/features/switch-wallet/WalletUnlockMod
import { TransactionDetailsModalProps } from '@/features/transactionsDisplay/transactionDetailsModal/TransactionDetailsModal'
import { SignMessageModalProps } from '@/features/walletConnect/SignMessageModal'
import { SignUnsignedTxModalProps } from '@/features/walletConnect/SignUnsignedTxModal'
import { WalletConnectSessionProposalModalProps } from '@/features/walletConnect/WalletConnectSessionProposalModal'
import { AddressSweepModalProps } from '@/modals/AddressSweepModal'
import { ConfirmModalProps } from '@/modals/ConfirmModal'
import { ConsolidateUTXOsModalProps } from '@/modals/ConsolidateUTXOsModal'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ You should have received a copy of the GNU Lesser General Public License
along with the library. If not, see <http://www.gnu.org/licenses/>.
*/

import { AddressHash, isNetworkValid, networkPresetSwitched, SessionProposalEvent } from '@alephium/shared'
import { ChainInfo, isCompatibleAddressGroup } from '@alephium/walletconnect-provider'
import { CoreTypes, ProposalTypes, SessionTypes } from '@walletconnect/types'
import { AddressHash, isNetworkValid, WalletConnectSessionProposalModalProps } from '@alephium/shared'
import { useWalletConnectNetwork } from '@alephium/shared-react'
import { isCompatibleAddressGroup } from '@alephium/walletconnect-provider'
import { SessionTypes } from '@walletconnect/types'
import { getSdkError } from '@walletconnect/utils'
import { AlertTriangle, PlusSquare } from 'lucide-react'
import { memo, useEffect, useState } from 'react'
Expand Down Expand Up @@ -49,16 +50,6 @@ import { Address } from '@/types/addresses'
import { getRandomLabelColor } from '@/utils/colors'
import { cleanUrl } from '@/utils/misc'

export interface WalletConnectSessionProposalModalProps {
chain: string
proposalEventId: SessionProposalEvent['id']
requiredNamespaceMethods: ProposalTypes.BaseRequiredNamespace['methods']
requiredNamespaceEvents: ProposalTypes.BaseRequiredNamespace['events']
metadata: CoreTypes.Metadata
chainInfo: ChainInfo
relayProtocol?: string
}

const WalletConnectSessionProposalModal = memo(
({
id: modalId,
Expand Down Expand Up @@ -86,18 +77,12 @@ const WalletConnectSessionProposalModal = memo(

const group = chainInfo.addressGroup

const showNetworkWarning = chainInfo.networkId && !isNetworkValid(chainInfo.networkId, currentNetworkId)
const { handleSwitchNetworkPress, showNetworkWarning } = useWalletConnectNetwork(chainInfo.networkId)

useEffect(() => {
setSignerAddressHash(addressesInGroup.find((a) => a === defaultAddress.hash) ?? addressesInGroup[0])
}, [addressesInGroup, defaultAddress.hash])

const handleSwitchNetworkPress = () => {
if (chainInfo.networkId === 'mainnet' || chainInfo.networkId === 'testnet' || chainInfo.networkId === 'devnet') {
dispatch(networkPresetSwitched(chainInfo.networkId))
}
}

const generateAddressInGroup = async () => {
try {
const address = await generateAddress(group)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { walletConnectPairingFailed, walletConnectProposalValidationFailed } fro
import { isRcVersion } from '@/utils/app-data'

export interface WalletConnectContextProps {
walletConnectClient?: SignClient
pairWithDapp: (uri: string) => void
unpairFromDapp: (pairingTopic: string) => Promise<void>
activeSessions: SessionTypes.Struct[]
Expand All @@ -67,7 +68,6 @@ export interface WalletConnectContextProps {
sessionRequestEvent: SessionRequestEvent,
error: ReturnType<typeof getSdkError>
) => Promise<void>
walletConnectClient?: SignClient
pendingDappConnectionUrl?: string
}

Expand Down
3 changes: 2 additions & 1 deletion apps/mobile-wallet/locales/en-US/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -398,5 +398,6 @@
"Save fund password": "Save fund password",
"Decrypt": "Decrypt",
"Warning": "Warning",
"No assets there, yet.": "No assets there, yet."
"No assets there, yet.": "No assets there, yet.",
"There is something wrong in the received WalletConnect data.": "There is something wrong in the received WalletConnect data."
}
Loading
Loading