// Check for any wallet on device
do {
let isOnDevice = try await portal.isWalletOnDevice()
if isOnDevice {
print("Wallet shares found on device")
} else {
print("No wallet shares on device")
}
} catch {
print("Error checking wallet presence: \(error)")
}
// Check for specific chain wallets
do {
// Check Ethereum wallet
let ethOnDevice = try await portal.isWalletOnDevice("eip155:1")
if ethOnDevice {
print("Ethereum wallet shares found on device")
}
// Check Solana wallet
let solOnDevice = try await portal.isWalletOnDevice("solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp")
if solOnDevice {
print("Solana wallet shares found on device")
}
} catch {
print("Error checking chain-specific wallets: \(error)")
}
// Complete example with recovery flow
do {
let isOnDevice = try await portal.isWalletOnDevice()
if !isOnDevice {
// Check if wallet exists and could be used to recover the wallet
if try await portal.isWalletRecoverable() {
// Recover wallet using available backup method
let methods = try await portal.availableRecoveryMethods()
if methods.contains(.iCloud) {
let recovered = try await portal.recoverWallet(.iCloud)
print("Recovered wallet with address: \(recovered.ethereum)")
}
} else {
// Create new wallet if none exists
let newWallet = try await portal.createWallet()
print("Created new wallet with ETH address: \(newWallet.ethereum)")
}
} else {
// Wallet is on device, verify it's working
let addresses = try await portal.getAddresses()
if let ethAddress = addresses[.eip155] {
print("Active ETH address: \(ethAddress ?? "Not found")")
}
}
} catch {
print("Error in wallet management flow: \(error)")
}