Transfer Operations
Relevant source files
- LinkSDK/Models/Payload.swift
- LinkSDKExample/LaunchScreen.storyboard
- LinkSDKExample/Main.storyboard
- README.md
This document covers the cryptocurrency transfer functionality within the LinkSDK, specifically how the SDK handles the execution, monitoring, and completion of financial transfers between accounts and external wallets. Transfer operations represent the final step in the user's financial workflow after establishing connections to institutions.
For information about establishing initial connections to financial institutions, see Integration Connection. For details about detecting and launching external wallet applications, see External App Integration.
Transfer Workflow Architecture
The transfer operations in LinkSDK follow a web-to-native communication pattern where transfers are initiated and monitored through the web interface, with completion results communicated back to the iOS application through JavaScript message handlers.
"Host Application""onTransferFinished""WKScriptMessageHandler""LinkWebViewViewController""Web Interface""Host Application""onTransferFinished""WKScriptMessageHandler""LinkWebViewViewController""Web Interface"alt[Transfer Success][Transfer Error]"User initiates transfer""Display transfer interface""Process transfer execution""transferFinished message""Parse TransferFinishedPayload""TransferFinishedSuccessPayload""TransferFinishedErrorPayload""Transfer completion notification"
Sources: LinkSDK/LinkWebViewController/LinkWebViewViewController.swift381-466
Transfer Message Types
The SDK defines specific JavaScript message types to handle different stages of transfer operations. The core transfer-related message type is processed through the JSMessageType enum.
Web JavaScript
jsMessageHandler
JSMessageType.transferFinished
TransferFinishedStatus
transferFinishedSuccess
transferFinishedError
TransferFinishedSuccessPayload
TransferFinishedErrorPayload
onTransferFinished(.success)
onTransferFinished(.error)
Sources: LinkSDK/LinkWebViewController/LinkWebViewViewController.swift50-61 LinkSDK/LinkWebViewController/LinkWebViewViewController.swift63-66
Transfer Data Models
The SDK provides structured data models to represent transfer completion states and associated metadata. These models ensure type-safe handling of transfer results.
| Data Structure | Purpose | Key Fields |
|---|---|---|
TransferFinishedPayload |
Root payload enum | .success(), .error() |
TransferFinishedSuccessPayload |
Successful transfer details | txId, txHash, symbol, amount |
TransferFinishedErrorPayload |
Transfer failure information | errorMessage |
TransferFinishedSuccessPayload Structure
The success payload contains comprehensive transaction metadata:
TransferFinishedSuccessPayload
+String? txId
+String? transferId
+String? txHash
+String? fromAddress
+String? toAddress
+String symbol
+Double amount
+Double? amountInFiat
+Double? totalAmountInFiat
+String? networkId
+String? networkName
The symbol and amount fields are required, representing the cryptocurrency symbol and transfer amount respectively. Optional fields provide additional context including blockchain transaction hashes, wallet addresses, fiat conversion amounts, and network identifiers.
Sources: LinkSDK/Models/Payload.swift65-77
Transfer Message Processing
The LinkWebViewViewController implements WKScriptMessageHandler to process transfer completion messages from the web interface. The message processing flow handles both successful and failed transfer scenarios.
userContentController didReceive message
Extract message type
JSMessageType.transferFinished
Extract status from payload
TransferFinishedStatus.transferFinishedSuccess
TransferFinishedStatus.transferFinishedError
JSONDecoder decode TransferFinishedSuccessPayload
JSONDecoder decode TransferFinishedErrorPayload
configuration.onTransferFinished?(.success)
configuration.onTransferFinished?(.error)
The message handler extracts the payload dictionary from the JavaScript message, determines the transfer status, and decodes the appropriate payload structure using JSONDecoder before invoking the configured callback.
Sources: LinkSDK/LinkWebViewController/LinkWebViewViewController.swift403-418
Configuration Integration
Transfer operations integrate with the SDK's configuration system through the LinkConfiguration.onTransferFinished callback property. This callback allows the host application to receive and process transfer completion events.
The callback signature accepts a TransferFinishedPayload enum value:
onTransferFinished: ((TransferFinishedPayload) -> Void)?
The host application can pattern match on the payload to handle success and error cases appropriately:
switch transferPayload {
case .success(let successPayload):
// Handle successful transfer
case .error(let errorPayload):
// Handle transfer error
}
Sources: LinkSDK/LinkWebViewController/LinkWebViewViewController.swift412 LinkSDK/LinkWebViewController/LinkWebViewViewController.swift417 LinkSDK/Models/Payload.swift60-63
Error Handling
Transfer errors are communicated through the TransferFinishedErrorPayload structure, which provides a simple error message string. The error handling follows the same JavaScript-to-native message pattern as successful transfers.
Transfer Error in Web
transferFinished with error status
TransferFinishedErrorPayload
onTransferFinished(.error)
Application Error Handling
The error payload contains a single errorMessage field that provides human-readable error information to the host application.
Sources: LinkSDK/Models/Payload.swift79-81 LinkSDK/LinkWebViewController/LinkWebViewViewController.swift413-417