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

chore: basic lab page improvements #3734

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
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
54 changes: 0 additions & 54 deletions apps/laboratory/src/components/UPA/UpaEvmSignMessageTest.tsx

This file was deleted.

138 changes: 138 additions & 0 deletions apps/laboratory/src/components/UPA/UpaSignMessageTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import * as React from 'react'

import { Button } from '@chakra-ui/react'
import Provider from '@walletconnect/universal-provider'
import base58 from 'bs58'

import { useAppKitAccount, useAppKitNetwork, useAppKitProvider } from '@reown/appkit/react'

import { BitcoinUtil } from '../../utils/BitcoinUtil'
import { ConstantsUtil } from '../../utils/ConstantsUtil'
import { useChakraToast } from '../Toast'

export function UpaSignMessageTest() {
const toast = useChakraToast()
const { isConnected, address } = useAppKitAccount()
const { caipNetwork } = useAppKitNetwork()

if (!caipNetwork) {
return null
}

const { walletProvider } = useAppKitProvider<Provider>(caipNetwork.chainNamespace)

async function getPayload() {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const map: Record<string, { method: string; params: any }> = {
solana: {
method: 'solana_signMessage',
params: {
message: base58.encode(new TextEncoder().encode('Hello Appkit!')),
pubkey: address
}
},
eip155: {
method: 'personal_sign',
params: [address, 'Hello AppKit!']
},
bip122: {
method: 'signPsbt',
params: {
psbt: '',
account: address
}
},
polkadot: {
method: 'polkadot_signMessage',
params: {
transactionPayload: {
specVersion: '0x00002468',
transactionVersion: '0x0000000e',
address: `${address}`,
blockHash: '0x554d682a74099d05e8b7852d19c93b527b5fae1e9e1969f6e1b82a2f09a14cc9',
blockNumber: '0x00cb539c',
era: '0xc501',
genesisHash: '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e',
method: '0x0001784920616d207369676e696e672074686973207472616e73616374696f6e21',
nonce: '0x00000000',
signedExtensions: [
'CheckNonZeroSender',
'CheckSpecVersion',
'CheckTxVersion',
'CheckGenesis',
'CheckMortality',
'CheckNonce',
'CheckWeight',
'ChargeTransactionPayment'
],
tip: '0x00000000000000000000000000000000',
version: 4
},
address
}
}
}

const payload = map[caipNetwork?.chainNamespace || '']

if (payload && address && caipNetwork?.chainNamespace === 'bip122') {
const utxos = await BitcoinUtil.getUTXOs(address, caipNetwork.caipNetworkId)
const feeRate = await BitcoinUtil.getFeeRate()

const { psbt } = BitcoinUtil.createSignPSBTParams({
amount: 1000,
feeRate,
network: caipNetwork,
recipientAddress: address,
senderAddress: address,
utxos
})

payload.params.psbt = psbt
}

return payload
}

async function onSignMessage() {
try {
if (!walletProvider || !address) {
throw Error('user is disconnected')
}

const payload = await getPayload()

if (!payload) {
throw Error('Chain not supported by laboratory')
}

await walletProvider.request(payload, caipNetwork?.caipNetworkId)

toast({
title: ConstantsUtil.SigningSucceededToastTitle,
description: 'Success',
type: 'success'
})
} catch (error) {
toast({
title: ConstantsUtil.SigningFailedToastTitle,
description: 'Failed to sign message',
type: 'error'
})
}
}

return (
<>
<Button
disabled={!isConnected}
data-testid="sign-message-button"
onClick={onSignMessage}
width="auto"
>
Sign Message
</Button>
<div data-testid="w3m-signature" hidden></div>
</>
)
}
61 changes: 0 additions & 61 deletions apps/laboratory/src/components/UPA/UpaSolanaSignMessageTest.tsx

This file was deleted.

13 changes: 2 additions & 11 deletions apps/laboratory/src/components/UPA/UpaTests.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { Box, Card, CardBody, CardHeader, Heading, Stack, StackDivider } from '@chakra-ui/react'

import { useAppKitNetwork } from '@reown/appkit/react'

import { UpaEvmSignMessageTest } from './UpaEvmSignMessageTest'
import { UpaSolanaSignMessageTest } from './UpaSolanaSignMessageTest'
import { UpaSignMessageTest } from './UpaSignMessageTest'

export function UpaTests() {
const { caipNetwork } = useAppKitNetwork()

return (
<Card marginTop={10} marginBottom={10}>
<CardHeader>
Expand All @@ -19,11 +14,7 @@ export function UpaTests() {
<Heading size="xs" textTransform="uppercase" pb="2">
Sign Message
</Heading>
{caipNetwork?.chainNamespace === 'eip155' ? (
<UpaEvmSignMessageTest />
) : (
<UpaSolanaSignMessageTest />
)}
<UpaSignMessageTest />
</Box>
</Stack>
</CardBody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react'

import Provider, { UniversalProvider } from '@walletconnect/universal-provider'

import { mainnet } from '@reown/appkit/networks'
import { type AppKitNetwork, mainnet } from '@reown/appkit/networks'
import { AppKit, createAppKit } from '@reown/appkit/react'

import { AppKitButtons } from '../../components/AppKitButtons'
Expand All @@ -11,7 +11,10 @@ import { UpaTests } from '../../components/UPA/UpaTests'
import { ConstantsUtil } from '../../utils/ConstantsUtil'
import { ThemeStore } from '../../utils/StoreUtil'

const networks = ConstantsUtil.EvmNetworks
const networks = [...ConstantsUtil.AllNetworks, ...ConstantsUtil.BitcoinNetworks] as [
AppKitNetwork,
...AppKitNetwork[]
]

export default function MultiChainWagmiAdapterOnly() {
const [uprovider, setUprovider] = useState<Provider | null>(null)
Expand Down
17 changes: 2 additions & 15 deletions apps/laboratory/src/pages/library/multichain-basic.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type AppKitNetwork, defineChain, mainnet } from '@reown/appkit/networks'
import { type AppKitNetwork, mainnet } from '@reown/appkit/networks'
import { createAppKit } from '@reown/appkit/react'

import { AppKitButtons } from '../../components/AppKitButtons'
Expand All @@ -7,20 +7,7 @@ import { UpaTests } from '../../components/UPA/UpaTests'
import { ConstantsUtil } from '../../utils/ConstantsUtil'
import { ThemeStore } from '../../utils/StoreUtil'

const networks = [
...ConstantsUtil.AllNetworks,
defineChain({
id: '91b171bb158e2d3848fa23a9f1c25182',
name: 'Polkadot',
network: 'polkadot',
nativeCurrency: { name: 'Polkadot', symbol: 'DOT', decimals: 18 },
rpcUrls: {
default: { http: ['https://rpc.polkadot.io'] }
},
chainNamespace: 'polkadot',
caipNetworkId: 'polkadot:mainnet'
})
]
const networks = [...ConstantsUtil.AllNetworks, ...ConstantsUtil.BitcoinNetworks]

const modal = createAppKit({
networks: networks as [AppKitNetwork, ...AppKitNetwork[]],
Expand Down
2 changes: 1 addition & 1 deletion packages/appkit/exports/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const PACKAGE_VERSION = '1.6.4'
export const PACKAGE_VERSION = '1.6.5'
2 changes: 1 addition & 1 deletion packages/appkit/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class AppKit {
// -- Public -------------------------------------------------------------------
public async open(options?: OpenOptions) {
await this.injectModalUi()
if (options?.uri && this.universalAdapter) {
if (options?.uri && this.universalProvider) {
ConnectionController.setUri(options.uri)
}
ModalController.open(options)
Expand Down
Loading