Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/reown-com/appkit
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvoskamp committed Nov 15, 2024
2 parents ecab080 + 89e7886 commit 2c7cd61
Show file tree
Hide file tree
Showing 54 changed files with 763 additions and 50 deletions.
24 changes: 0 additions & 24 deletions .changeset/pink-rockets-explain.md

This file was deleted.

12 changes: 12 additions & 0 deletions apps/demo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @apps/demo

## 1.4.0

### Minor Changes

- [#3076](https://github.com/reown-com/appkit/pull/3076) [`1bd3dc7`](https://github.com/reown-com/appkit/commit/1bd3dc70850257dd8db523499e8a38e3a0f2ac4a) Thanks [@svenvoskamp](https://github.com/svenvoskamp)! - Implementing new architecture design for better handling and scalibity of the various adapters

### Patch Changes

- Updated dependencies [[`1bd3dc7`](https://github.com/reown-com/appkit/commit/1bd3dc70850257dd8db523499e8a38e3a0f2ac4a)]:
- @reown/appkit-adapter-wagmi@1.4.0
- @reown/appkit@1.4.0

## 1.3.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion apps/demo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@apps/demo",
"version": "1.3.2",
"version": "1.4.0",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
12 changes: 12 additions & 0 deletions apps/gallery/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @apps/gallery

## 1.4.0

### Minor Changes

- [#3076](https://github.com/reown-com/appkit/pull/3076) [`1bd3dc7`](https://github.com/reown-com/appkit/commit/1bd3dc70850257dd8db523499e8a38e3a0f2ac4a) Thanks [@svenvoskamp](https://github.com/svenvoskamp)! - Implementing new architecture design for better handling and scalibity of the various adapters

### Patch Changes

- Updated dependencies [[`1bd3dc7`](https://github.com/reown-com/appkit/commit/1bd3dc70850257dd8db523499e8a38e3a0f2ac4a)]:
- @reown/appkit-common@1.4.0
- @reown/appkit-ui@1.4.0

## 1.3.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion apps/gallery/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@apps/gallery",
"version": "1.3.2",
"version": "1.4.0",
"private": true,
"main": "index.js",
"scripts": {
Expand Down
19 changes: 19 additions & 0 deletions apps/laboratory/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# @apps/laboratory

## 1.4.0

### Minor Changes

- [#3076](https://github.com/reown-com/appkit/pull/3076) [`1bd3dc7`](https://github.com/reown-com/appkit/commit/1bd3dc70850257dd8db523499e8a38e3a0f2ac4a) Thanks [@svenvoskamp](https://github.com/svenvoskamp)! - Implementing new architecture design for better handling and scalibity of the various adapters

### Patch Changes

- Updated dependencies [[`1bd3dc7`](https://github.com/reown-com/appkit/commit/1bd3dc70850257dd8db523499e8a38e3a0f2ac4a)]:
- @reown/appkit-adapter-ethers5@1.4.0
- @reown/appkit-adapter-ethers@1.4.0
- @reown/appkit-adapter-solana@1.4.0
- @reown/appkit-adapter-wagmi@1.4.0
- @reown/appkit-experimental@1.4.0
- @reown/appkit@1.4.0
- @reown/appkit-wallet@1.4.0
- @reown/appkit-siwe@1.4.0
- @reown/appkit-siwx@1.4.0

## 1.3.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion apps/laboratory/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@apps/laboratory",
"type": "module",
"version": "1.3.2",
"version": "1.4.0",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, Input, Stack, Text, Tooltip } from '@chakra-ui/react'
import { useAccount } from 'wagmi'
import { useSendCalls } from 'wagmi/experimental'
import { useCallback, useState } from 'react'
import { useCallback, useMemo, useState } from 'react'
import { useChakraToast } from '../Toast'
import { parseGwei, type Address } from 'viem'
import { vitalikEthAddress } from '../../utils/DataUtil'
Expand All @@ -18,6 +18,19 @@ const TEST_TX_2 = {
data: '0xdeadbeef' as `0x${string}`
}

const BICONOMY_PAYMASTER_CONTEXT = {
mode: 'SPONSORED',
calculateGasLimits: false,
expiryDuration: 300,
sponsorshipInfo: {
webhookData: {},
smartAccountInfo: {
name: 'SAFE',
version: '1.4.1'
}
}
}

export function WagmiSendCallsWithPaymasterServiceTest() {
const { provider, supportedChains, supportedChainsName, currentChainsInfo, supported } =
useWagmiAvailableCapabilities({
Expand Down Expand Up @@ -66,11 +79,32 @@ export function WagmiSendCallsWithPaymasterServiceTest() {
}

function AvailableTestContent() {
const [paymasterProvider, setPaymasterProvider] = useState<string>()
const [reownPolicyId, setReownPolicyId] = useState<string>('')
const [paymasterServiceUrl, setPaymasterServiceUrl] = useState<string>('')
const [isLoading, setLoading] = useState(false)

const toast = useChakraToast()

const context = useMemo(() => {
const contexts: Record<string, unknown> = {
biconomy: BICONOMY_PAYMASTER_CONTEXT,
reown: {
policyId: reownPolicyId
}
}

return contexts[paymasterProvider || '']
}, [paymasterProvider])

function onPaymasterUrlChange(url: string) {
setPaymasterServiceUrl(url)

const match = url.match(/pimlico|biconomy|reown/u)
if (match?.[0]) {
setPaymasterProvider(match?.[0])
}
}

const { sendCalls } = useSendCalls({
mutation: {
onSuccess: hash => {
Expand Down Expand Up @@ -101,7 +135,8 @@ function AvailableTestContent() {
calls: [TEST_TX_1, TEST_TX_2],
capabilities: {
paymasterService: {
url: paymasterServiceUrl
url: paymasterServiceUrl,
context
}
}
})
Expand All @@ -112,13 +147,23 @@ function AvailableTestContent() {
<Tooltip label="Paymaster Service URL should be of ERC-7677 paymaster service proxy">
<Input
placeholder="http://api.pimlico.io/v2/sepolia/rpc?apikey=..."
onChange={e => setPaymasterServiceUrl(e.target.value)}
onChange={e => onPaymasterUrlChange(e.target.value)}
value={paymasterServiceUrl}
isDisabled={isLoading}
whiteSpace="nowrap"
textOverflow="ellipsis"
/>
</Tooltip>
{paymasterProvider === 'reown' && (
<Input
placeholder="Reown Policy ID (Optional)"
onChange={e => setReownPolicyId(e.target.value)}
value={reownPolicyId}
isDisabled={isLoading}
whiteSpace="nowrap"
textOverflow="ellipsis"
/>
)}
<Button
width={'fit-content'}
data-testid="send-calls-paymaster-service-button"
Expand Down
19 changes: 19 additions & 0 deletions packages/adapters/ethers/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# @reown/appkit-adapter-ethers

## 1.4.0

### Minor Changes

- [#3076](https://github.com/reown-com/appkit/pull/3076) [`1bd3dc7`](https://github.com/reown-com/appkit/commit/1bd3dc70850257dd8db523499e8a38e3a0f2ac4a) Thanks [@svenvoskamp](https://github.com/svenvoskamp)! - Implementing new architecture design for better handling and scalibity of the various adapters

### Patch Changes

- Updated dependencies [[`1bd3dc7`](https://github.com/reown-com/appkit/commit/1bd3dc70850257dd8db523499e8a38e3a0f2ac4a)]:
- @reown/appkit-utils@1.4.0
- @reown/appkit-scaffold-ui@1.4.0
- @reown/appkit-polyfills@1.4.0
- @reown/appkit@1.4.0
- @reown/appkit-common@1.4.0
- @reown/appkit-wallet@1.4.0
- @reown/appkit-core@1.4.0
- @reown/appkit-siwe@1.4.0
- @reown/appkit-ui@1.4.0

## 1.3.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/adapters/ethers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reown/appkit-adapter-ethers",
"version": "1.3.2",
"version": "1.4.0",
"type": "module",
"main": "./dist/esm/src/index.js",
"types": "./dist/types/src/index.d.ts",
Expand Down
42 changes: 42 additions & 0 deletions packages/adapters/ethers/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { formatEther, InfuraProvider, JsonRpcProvider } from 'ethers'
import { CoinbaseWalletSDK, type ProviderInterface } from '@coinbase/wallet-sdk'
import type { W3mFrameProvider } from '@reown/appkit-wallet'
import { EthersMethods } from './utils/EthersMethods.js'
import { ProviderUtil } from '@reown/appkit/store'

export interface EIP6963ProviderDetail {
info: Connector['info']
Expand Down Expand Up @@ -542,4 +543,45 @@ export class EthersAdapter extends AdapterBlueprint {
console.info('Could not revoke permissions from wallet. Disconnecting...', error)
}
}

public async getCapabilities(params: AdapterBlueprint.GetCapabilitiesParams): Promise<unknown> {
const provider = ProviderUtil.getProvider(CommonConstantsUtil.CHAIN.EVM)

if (!provider) {
throw new Error('Provider is undefined')
}

const walletCapabilitiesString = provider.session?.sessionProperties?.['capabilities']
if (walletCapabilitiesString) {
const walletCapabilities = EthersMethods.parseWalletCapabilities(walletCapabilitiesString)
const accountCapabilities = walletCapabilities[params]
if (accountCapabilities) {
return accountCapabilities
}
}

return await provider.request({ method: 'wallet_getCapabilities', params: [params] })
}

public async grantPermissions(params: AdapterBlueprint.GrantPermissionsParams): Promise<unknown> {
const provider = ProviderUtil.getProvider(CommonConstantsUtil.CHAIN.EVM)

if (!provider) {
throw new Error('Provider is undefined')
}

return await provider.request({ method: 'wallet_grantPermissions', params })
}

public async revokePermissions(
params: AdapterBlueprint.RevokePermissionsParams
): Promise<`0x${string}`> {
const provider = ProviderUtil.getProvider(CommonConstantsUtil.CHAIN.EVM)

if (!provider) {
throw new Error('Provider is undefined')
}

return await provider.request({ method: 'wallet_revokePermissions', params: [params] })
}
}
57 changes: 57 additions & 0 deletions packages/adapters/ethers/src/tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import UniversalProvider from '@walletconnect/universal-provider'
import { JsonRpcProvider, InfuraProvider } from 'ethers'
import { mainnet } from '@reown/appkit/networks'
import { EthersMethods } from '../utils/EthersMethods'
import { ProviderUtil } from '@reown/appkit/store'

// Mock external dependencies
vi.mock('ethers', async importOriginal => {
Expand Down Expand Up @@ -320,4 +321,60 @@ describe('EthersAdapter', () => {
expect(result).toBe('1.5')
})
})

describe('EthersAdapter - Permissions', () => {
const mockProvider = {
request: vi.fn()
} as unknown as UniversalProvider

beforeEach(() => {
vi.spyOn(ProviderUtil, 'getProvider').mockImplementation(() => mockProvider)
})

it('should call wallet_getCapabilities', async () => {
await adapter.getCapabilities('eip155:1:0x123')

expect(mockProvider.request).toHaveBeenCalledWith({
method: 'wallet_getCapabilities',
params: ['eip155:1:0x123']
})
})

it('should call wallet_grantPermissions', async () => {
const mockParams = {
pci: 'test-pci',
expiry: 1234567890,
address: '0x123',
permissions: ['eth_accounts']
}

await adapter.grantPermissions(mockParams)

expect(mockProvider.request).toHaveBeenCalledWith({
method: 'wallet_grantPermissions',
params: mockParams
})
})

it('should call wallet_revokePermissions', async () => {
vi.mocked(mockProvider.request).mockImplementation(() =>
Promise.resolve('0x123' as `0x${string}`)
)

const mockParams = {
pci: 'test-pci',
expiry: 1234567890,
address: '0x123' as `0x${string}`,
permissions: ['eth_accounts']
}

const result = await adapter.revokePermissions(mockParams)

expect(mockProvider.request).toHaveBeenCalledWith({
method: 'wallet_revokePermissions',
params: [mockParams]
})
expect(result).toBe('0x123')
})
})
})
19 changes: 19 additions & 0 deletions packages/adapters/ethers5/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# @reown/appkit-adapter-ethers5

## 1.4.0

### Minor Changes

- [#3076](https://github.com/reown-com/appkit/pull/3076) [`1bd3dc7`](https://github.com/reown-com/appkit/commit/1bd3dc70850257dd8db523499e8a38e3a0f2ac4a) Thanks [@svenvoskamp](https://github.com/svenvoskamp)! - Implementing new architecture design for better handling and scalibity of the various adapters

### Patch Changes

- Updated dependencies [[`1bd3dc7`](https://github.com/reown-com/appkit/commit/1bd3dc70850257dd8db523499e8a38e3a0f2ac4a)]:
- @reown/appkit-utils@1.4.0
- @reown/appkit-scaffold-ui@1.4.0
- @reown/appkit-polyfills@1.4.0
- @reown/appkit@1.4.0
- @reown/appkit-common@1.4.0
- @reown/appkit-wallet@1.4.0
- @reown/appkit-core@1.4.0
- @reown/appkit-siwe@1.4.0
- @reown/appkit-ui@1.4.0

## 1.3.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/adapters/ethers5/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reown/appkit-adapter-ethers5",
"version": "1.3.2",
"version": "1.4.0",
"type": "module",
"main": "./dist/esm/src/index.js",
"types": "./dist/types/src/index.d.ts",
Expand Down
Loading

0 comments on commit 2c7cd61

Please sign in to comment.