Skip to content

Commit

Permalink
Merge branch 'main' into fix/siwe-chain-id
Browse files Browse the repository at this point in the history
  • Loading branch information
tomiir authored Sep 9, 2024
2 parents 0c6bd8a + ff38a6a commit 9f9bc43
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 62 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ui_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ on:
secrets:
NEXT_PUBLIC_PROJECT_ID:
required: true
RELEASE_TOKEN_V2:
required: true
TFC_INFRA_TOKEN:
required: true
TESTS_NEXTAUTH_SECRET:
required: false
TESTS_MAILSAC_API_KEY:
Expand All @@ -54,7 +58,7 @@ jobs:
labels: playwright
count: 5
secrets:
GITHUB_PAT: ${{ secrets.RELEASE_TOKEN }}
GITHUB_PAT: ${{ secrets.RELEASE_TOKEN_V2 }}
TF_API_TOKEN: ${{ secrets.TFC_INFRA_TOKEN }}

ui_tests:
Expand Down
2 changes: 1 addition & 1 deletion apps/laboratory/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const cspHeader = `
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
img-src * 'self' data: blob: https://walletconnect.org https://walletconnect.com https://secure.walletconnect.com https://secure.walletconnect.org https://tokens-data.1inch.io https://tokens.1inch.io https://ipfs.io https://lab.web3modal.com;
font-src 'self' https://fonts.gstatic.com;
connect-src 'self' https://react-wallet.walletconnect.com https://rpc.walletconnect.com https://rpc.walletconnect.org https://relay.walletconnect.com https://relay.walletconnect.org wss://relay.walletconnect.com wss://relay.walletconnect.org https://pulse.walletconnect.com https://pulse.walletconnect.org https://api.web3modal.com https://api.web3modal.org wss://www.walletlink.org https://o1095249.ingest.sentry.io;
connect-src 'self' https://react-wallet.walletconnect.com https://rpc.walletconnect.com https://rpc.walletconnect.org https://relay.walletconnect.com https://relay.walletconnect.org wss://relay.walletconnect.com wss://relay.walletconnect.org https://pulse.walletconnect.com https://pulse.walletconnect.org https://api.web3modal.com https://api.web3modal.org wss://www.walletlink.org https://o1095249.ingest.sentry.io https://quote-api.jup.ag;
frame-src 'self' https://verify.walletconnect.com https://verify.walletconnect.org https://secure.walletconnect.com https://secure.walletconnect.org ${
process.env.NEXT_PUBLIC_SECURE_SITE_SDK_URL || ''
};
Expand Down
16 changes: 8 additions & 8 deletions apps/laboratory/public/.well-known/apple-app-site-association
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@
]
},
{
"appID": "W5R8AG9K22.com.walletconnect.web3modal.rnsample",
"appID": "W5R8AG9K22.com.walletconnect.web3modal.rnsample.internal",
"paths": [
"/rn_appkit*"
"/rn_appkit_internal"
]
},
{
"appID": "W5R8AG9K22.com.walletconnect.web3modal.rnsample.internal",
"appID": "W5R8AG9K22.com.walletconnect.web3modal.rnsample",
"paths": [
"/rn_appkit*"
"/rn_appkit"
]
},
{
"appID": "W5R8AG9K22.com.walletconnect.web3wallet.rnsample",
"appID": "W5R8AG9K22.com.walletconnect.web3wallet.rnsample.internal",
"paths": [
"/rn_walletkit*"
"/rn_walletkit_internal"
]
},
{
"appID": "W5R8AG9K22.com.walletconnect.web3wallet.rnsample.internal",
"appID": "W5R8AG9K22.com.walletconnect.web3wallet.rnsample",
"paths": [
"/rn_walletkit*"
"/rn_walletkit"
]
},
{
Expand Down
20 changes: 20 additions & 0 deletions apps/laboratory/public/.well-known/assetlinks.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@
]
}
},
{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "com.walletconnect.web3wallet.rnsample.debug",
"sha256_cert_fingerprints": [
"3D:87:31:1C:66:8B:A0:CB:F9:F1:D5:28:3B:DF:2E:4F:CB:19:EA:AB:B4:B7:CE:C4:D9:E1:E0:6D:32:FB:C6:56"
]
}
},
{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
Expand All @@ -129,6 +139,16 @@
]
}
},
{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "com.walletconnect.web3modal.rnsample.debug",
"sha256_cert_fingerprints": [
"3D:87:31:1C:66:8B:A0:CB:F9:F1:D5:28:3B:DF:2E:4F:CB:19:EA:AB:B4:B7:CE:C4:D9:E1:E0:6D:32:FB:C6:56"
]
}
},
{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
Expand Down
122 changes: 122 additions & 0 deletions apps/laboratory/src/components/Solana/SolanaSignJupiterSwapTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { useState } from 'react'
import { Button, Stack, Text, Spacer } from '@chakra-ui/react'
import { PublicKey, VersionedTransaction } from '@solana/web3.js'

import { useWeb3ModalAccount, useWeb3ModalProvider } from '@web3modal/solana/react'

import { solana } from '../../utils/ChainsUtil'
import { useChakraToast } from '../Toast'
import bs58 from 'bs58'

export function SolanaSignJupiterSwapTest() {
const toast = useChakraToast()
const { chainId } = useWeb3ModalAccount()
const { walletProvider, connection } = useWeb3ModalProvider()
const [loading, setLoading] = useState(false)

async function onSignVersionedTransaction() {
try {
setLoading(true)
if (!walletProvider?.publicKey) {
throw Error('user is disconnected')
}

if (!connection) {
throw Error('no connection set')
}

const transaction = await createJupiterSwapTransaction({
publicKey: walletProvider.publicKey
})
const signedTransaction = await walletProvider.signTransaction(transaction)
const signature = signedTransaction.signatures[0]

if (!signature) {
throw Error('Empty signature')
}

toast({
title: 'Success',
description: bs58.encode(signature),
type: 'success'
})
} catch (err) {
toast({
title: 'Error',
description: (err as Error).message,
type: 'error'
})
} finally {
setLoading(false)
}
}

if (chainId === solana.chainId) {
return (
<Text fontSize="md" color="yellow">
Switch to Solana Devnet or Testnet to test this feature
</Text>
)
}

return (
<Stack direction={['column', 'column', 'row']}>
<Button
data-test-id="sign-transaction-button"
onClick={onSignVersionedTransaction}
isDisabled={loading}
>
Sign Jupiter Swap Transaction
</Button>
<Spacer />
</Stack>
)
}

type CreateJupiterSwapTransactionParams = {
publicKey: PublicKey
}

async function createJupiterSwapTransaction({ publicKey }: CreateJupiterSwapTransactionParams) {
const qs = new URLSearchParams({
inputMint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
outputMint: 'So11111111111111111111111111111111111111112',
amount: '100000',
slippageBps: '300',
swapMode: 'ExactIn',
onlyDirectRoutes: 'false',
asLegacyTransaction: 'false',
maxAccounts: '64',
minimizeSlippage: 'false'
})

const quoteResponse = await (
await fetch(`https://quote-api.jup.ag/v6/quote?${qs.toString()}`)
).json()
const swapResponse = await (
await fetch('https://quote-api.jup.ag/v6/swap', {
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
userPublicKey: publicKey.toString(),
wrapAndUnwrapSol: true,
prioritizationFeeLamports: {
priorityLevelWithMaxLamports: {
maxLamports: 4000000,
global: false,
priorityLevel: 'high'
}
},
asLegacyTransaction: false,
dynamicComputeUnitLimit: true,
allowOptimizedWrappedSolTokenAccount: false,
quoteResponse,
dynamicSlippage: { maxBps: 300 }
}),
method: 'POST'
})
).json()

return VersionedTransaction.deserialize(Buffer.from(swapResponse.swapTransaction, 'base64'))
}
14 changes: 14 additions & 0 deletions apps/laboratory/src/components/Solana/SolanaTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { SolanaWriteContractTest } from './SolanaWriteContractTest'
import { solana, solanaDevnet, solanaTestnet } from '../../utils/ChainsUtil'
import { SolanaSignAndSendTransaction } from './SolanaSignAndSendTransactionTest'
import { SolanaSignAllTransactionsTest } from './SolanaSignAllTransactionsTest'
import { SolanaSignJupiterSwapTest } from './SolanaSignJupiterSwapTest'

export function SolanaTests() {
const { isConnected, currentChain } = useWeb3ModalAccount()
Expand Down Expand Up @@ -83,6 +84,19 @@ export function SolanaTests() {
</Heading>
<SolanaSignAndSendTransaction />
</Box>

<Box>
<Heading size="xs" textTransform="uppercase" pb="2">
Sign Jupiter Swap Transaction
<Tooltip label="Use Jupiter Swap API to create a transaction that has Address Lookup Tables and requests for the wallet to sign it">
<Text as="span" fontSize="sm" ml="2">
ℹ️
</Text>
</Tooltip>
</Heading>
<SolanaSignJupiterSwapTest />
</Box>

{(currentChain?.chainId === solanaTestnet.chainId ||
currentChain?.chainId === solanaDevnet.chainId) && (
<Stack divider={<StackDivider />} spacing="4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
Connection,
PublicKey,
Transaction,
TransactionMessage,
VersionedTransaction,
type SendOptions
} from '@solana/web3.js'
Expand Down Expand Up @@ -284,18 +283,9 @@ export class WalletConnectProvider extends ProviderEventEmitter implements Provi
* This is a deprecated method that is used to support older versions of the
* WalletConnect RPC API. It should be removed in the future
*/
private getRawRPCParams(_transaction: AnyTransaction) {
let transaction = _transaction

private getRawRPCParams(transaction: AnyTransaction) {
if (isVersionedTransaction(transaction)) {
const instructions = TransactionMessage.decompile(transaction.message).instructions
const legacyMessage = new TransactionMessage({
payerKey: new PublicKey(this.getAccount(true).publicKey),
recentBlockhash: transaction.message.recentBlockhash,
instructions: [...instructions]
}).compileToLegacyMessage()

transaction = Transaction.populate(legacyMessage)
return {}
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,6 @@ describe('WalletConnectProvider specific tests', () => {
{
method: 'solana_signTransaction',
params: {
feePayer: '2VqKhjZ766ZN3uBtBpb7Ls3cN4HrocP1rzxzekhVEgoP',
instructions: [
{
data: '3Bxs4NN8M2Yn4TLb',
keys: [
{
isSigner: true,
isWritable: true,
pubkey: '2VqKhjZ766ZN3uBtBpb7Ls3cN4HrocP1rzxzekhVEgoP'
},
{
isSigner: true,
isWritable: true,
pubkey: '2VqKhjZ766ZN3uBtBpb7Ls3cN4HrocP1rzxzekhVEgoP'
}
],
programId: '11111111111111111111111111111111'
}
],
recentBlockhash: 'EZySCpmzXRuUtM95P2JGv9SitqYph6Nv6HaYBK7a8PKJ',
transaction:
'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQABAhY+loQT/3nqQuE+Gw4GLiTIklVzYfSLz1r9WQ1FedoGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADJmlOhYicUv7MMXLfh/CK3nuxRET//L6xrgHRfdADXpQEBAgAADAIAAACAlpgAAAAAAAA=',
pubkey: TestConstants.accounts[0].address
Expand Down Expand Up @@ -301,26 +281,6 @@ describe('WalletConnectProvider specific tests', () => {
{
method: 'solana_signTransaction',
params: {
feePayer: '2VqKhjZ766ZN3uBtBpb7Ls3cN4HrocP1rzxzekhVEgoP',
instructions: [
{
data: '3Bxs4NN8M2Yn4TLb',
keys: [
{
isSigner: true,
isWritable: true,
pubkey: '2VqKhjZ766ZN3uBtBpb7Ls3cN4HrocP1rzxzekhVEgoP'
},
{
isSigner: true,
isWritable: true,
pubkey: '2VqKhjZ766ZN3uBtBpb7Ls3cN4HrocP1rzxzekhVEgoP'
}
],
programId: '11111111111111111111111111111111'
}
],
recentBlockhash: 'EZySCpmzXRuUtM95P2JGv9SitqYph6Nv6HaYBK7a8PKJ',
transaction:
'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQABAhY+loQT/3nqQuE+Gw4GLiTIklVzYfSLz1r9WQ1FedoGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADJmlOhYicUv7MMXLfh/CK3nuxRET//L6xrgHRfdADXpQEBAgAADAIAAACAlpgAAAAAAAA=',
pubkey: TestConstants.accounts[0].address
Expand Down

0 comments on commit 9f9bc43

Please sign in to comment.