Skip to content

Commit

Permalink
Extract constants
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Sep 20, 2023
1 parent 0688b36 commit 5eb5938
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 44 deletions.
49 changes: 5 additions & 44 deletions src/components/wallet-connect/hooks/WalletConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,10 @@ import { type JsonRpcResponse } from '@walletconnect/jsonrpc-utils'
import type Web3WalletType from '@walletconnect/web3wallet'
import { type SafeInfo } from '@safe-global/safe-gateway-typescript-sdk'
import { type SessionTypes } from 'walletconnect-v2-types'
import { EVMBasedNamespaces, SAFE_COMPATIBLE_METHODS, SAFE_WALLET_METADATA, WC_ERRORS } from './constants'

const logger = IS_PRODUCTION ? undefined : 'debug'

const USER_DISCONNECTED_CODE = 6000

const EVMBasedNamespaces: string = 'eip155'

// see full list here: https://github.com/safe-global/safe-apps-sdk/blob/main/packages/safe-apps-provider/src/provider.ts#L35
export const compatibleSafeMethods: string[] = [
'eth_accounts',
'net_version',
'eth_chainId',
'personal_sign',
'eth_sign',
'eth_signTypedData',
'eth_signTypedData_v4',
'eth_sendTransaction',
'eth_blockNumber',
'eth_getBalance',
'eth_getCode',
'eth_getTransactionCount',
'eth_getStorageAt',
'eth_getBlockByNumber',
'eth_getBlockByHash',
'eth_getTransactionByHash',
'eth_getTransactionReceipt',
'eth_estimateGas',
'eth_call',
'eth_getLogs',
'eth_gasPrice',
'wallet_getPermissions',
'wallet_requestPermissions',
'safe_setSettings',
]

// MOVE TO CONSTANTS
export const SAFE_WALLET_METADATA = {
name: 'Safe Wallet',
description: 'The most trusted platform to manage digital assets on Ethereum',
url: 'https://app.safe.global',
icons: ['https://app.safe.global/favicons/mstile-150x150.png', 'https://app.safe.global/favicons/logo_120x120.png'],
}

export class WalletConnect {
private web3Wallet: Web3WalletType | undefined
private safe: SafeInfo
Expand Down Expand Up @@ -124,7 +85,7 @@ export class WalletConnect {
await this.web3Wallet.disconnectSession({
topic: this.currentSession.topic,
reason: {
code: USER_DISCONNECTED_CODE,
code: WC_ERRORS.USER_DISCONNECTED_CODE,
message: 'User disconnected. Safe Wallet Session ended by the user',
},
})
Expand Down Expand Up @@ -182,7 +143,7 @@ export class WalletConnect {
eip155: {
accounts: [safeAccount], // only the Safe account
chains: [safeChain], // only the Safe chain
methods: compatibleSafeMethods, // only the Safe methods
methods: SAFE_COMPATIBLE_METHODS, // only the Safe methods
events: safeEvents,
},
},
Expand All @@ -196,7 +157,7 @@ export class WalletConnect {
? safeOnRequiredChains
: [safeAccount, ...safeOnRequiredChains], // Add all required chains on top
chains: requiredChains, // return the required Safes
methods: compatibleSafeMethods, // only the Safe methods
methods: SAFE_COMPATIBLE_METHODS, // only the Safe methods
events: safeEvents,
},
},
Expand All @@ -219,7 +180,7 @@ export class WalletConnect {
eip155: {
accounts: [safeAccount],
chains: requiredChains,
methods: compatibleSafeMethods,
methods: SAFE_COMPATIBLE_METHODS,
events: safeEvents,
},
},
Expand Down
42 changes: 42 additions & 0 deletions src/components/wallet-connect/hooks/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export const SAFE_COMPATIBLE_METHODS = [
'eth_accounts',
'net_version',
'eth_chainId',
'personal_sign',
'eth_sign',
'eth_signTypedData',
'eth_signTypedData_v4',
'eth_sendTransaction',
'eth_blockNumber',
'eth_getBalance',
'eth_getCode',
'eth_getTransactionCount',
'eth_getStorageAt',
'eth_getBlockByNumber',
'eth_getBlockByHash',
'eth_getTransactionByHash',
'eth_getTransactionReceipt',
'eth_estimateGas',
'eth_call',
'eth_getLogs',
'eth_gasPrice',
'wallet_getPermissions',
'wallet_requestPermissions',
'safe_setSettings',
]

export enum WC_ERRORS {
UNSUPPORTED_CHAIN_ERROR_CODE = 5100,
INVALID_METHOD_ERROR_CODE = 1001,
USER_REJECTED_REQUEST_CODE = 4001,
USER_DISCONNECTED_CODE = 6000,
}

export const SAFE_WALLET_METADATA = {
name: 'Safe Wallet',
description: 'The most trusted platform to manage digital assets on Ethereum',
url: 'https://app.safe.global',
icons: ['https://app.safe.global/favicons/mstile-150x150.png', 'https://app.safe.global/favicons/logo_120x120.png'],
}

export const EVMBasedNamespaces = 'eip155'

0 comments on commit 5eb5938

Please sign in to comment.