Skip to content

added CAIP-25 to remove the round-trip required for wallet_getCapabilities #540

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

Merged
merged 3 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions advanced/wallets/react-wallet-v2/src/utils/EIP5792WalletUtil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { eip155Addresses } from './EIP155WalletUtil'
import { GetCapabilitiesResult, supportedEIP5792CapabilitiesForEOA, supportedEIP5792CapabilitiesForSCA } from '@/data/EIP5792Data'

export function getWalletCapabilities(addresses:string[]){
const walletCapabilities:GetCapabilitiesResult = {}
addresses.forEach(address => {
const namespacesAddress = address.split(':');
// address will be the last index element whether
// its a simple address or namespace:chainId:address
const addr = namespacesAddress[namespacesAddress.length - 1 ] ;

if(eip155Addresses.includes(addr) && Object.keys(supportedEIP5792CapabilitiesForEOA).length !== 0){
walletCapabilities[addr] = supportedEIP5792CapabilitiesForEOA
}

walletCapabilities[addr] = supportedEIP5792CapabilitiesForSCA

})
return walletCapabilities
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import SettingsStore from '@/store/SettingsStore'
import usePriorityAccounts from '@/hooks/usePriorityAccounts'
import useSmartAccounts from '@/hooks/useSmartAccounts'
import { EIP5792_METHODS } from '@/data/EIP5792Data'
import { getWalletCapabilities } from '@/utils/EIP5792WalletUtil'

const StyledText = styled(Text, {
fontWeight: 400
Expand Down Expand Up @@ -253,13 +254,17 @@ export default function SessionProposalModal() {
setIsLoadingApprove(true)
try {
if (reorderedEip155Accounts.length > 0) {
// we should append the smart accounts to the available eip155 accounts
namespaces.eip155.accounts = namespaces.eip155.accounts.concat(reorderedEip155Accounts)
// reorderedEip155Accounts includes Smart Accounts(if enabled) and EOA's
namespaces.eip155.accounts = reorderedEip155Accounts
}

//get capabilities for all reorderedEip155Accounts in wallet
const capabilities = getWalletCapabilities(reorderedEip155Accounts)
const sessionProperties = { capabilities: JSON.stringify(capabilities) }

await web3wallet.approveSession({
id: proposal.id,
namespaces
namespaces,
sessionProperties
})
SettingsStore.setSessions(Object.values(web3wallet.getActiveSessions()))
} catch (e) {
Expand Down