|
|
|
@ -5,18 +5,18 @@ import WebKit |
|
|
|
|
import JavaScriptCore |
|
|
|
|
|
|
|
|
|
enum WebViewType { |
|
|
|
|
case dappBrowser |
|
|
|
|
case dappBrowser(RPCServer) |
|
|
|
|
case tokenScriptRenderer |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
extension WKWebViewConfiguration { |
|
|
|
|
|
|
|
|
|
static func make(forType type: WebViewType, server: RPCServer, address: AlphaWallet.Address, in messageHandler: WKScriptMessageHandler) -> WKWebViewConfiguration { |
|
|
|
|
static func make(forType type: WebViewType, address: AlphaWallet.Address, in messageHandler: WKScriptMessageHandler) -> WKWebViewConfiguration { |
|
|
|
|
let webViewConfig = WKWebViewConfiguration() |
|
|
|
|
var js = "" |
|
|
|
|
|
|
|
|
|
switch type { |
|
|
|
|
case .dappBrowser: |
|
|
|
|
case .dappBrowser(let server): |
|
|
|
|
guard |
|
|
|
|
let bundlePath = Bundle.main.path(forResource: "AlphaWalletWeb3Provider", ofType: "bundle"), |
|
|
|
|
let bundle = Bundle(path: bundlePath) else { return webViewConfig } |
|
|
|
@ -28,7 +28,7 @@ extension WKWebViewConfiguration { |
|
|
|
|
} |
|
|
|
|
js += javaScriptForDappBrowser(server: server, address: address) |
|
|
|
|
case .tokenScriptRenderer: |
|
|
|
|
js += javaScriptForTokenScriptRenderer(server: server, address: address) |
|
|
|
|
js += javaScriptForTokenScriptRenderer(address: address) |
|
|
|
|
js += """ |
|
|
|
|
\n |
|
|
|
|
web3.tokens = { |
|
|
|
@ -141,7 +141,7 @@ extension WKWebViewConfiguration { |
|
|
|
|
""" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate static func javaScriptForTokenScriptRenderer(server: RPCServer, address: AlphaWallet.Address) -> String { |
|
|
|
|
fileprivate static func javaScriptForTokenScriptRenderer(address: AlphaWallet.Address) -> String { |
|
|
|
|
return """ |
|
|
|
|
window.web3CallBacks = {} |
|
|
|
|
window.tokenScriptCallBacks = {} |
|
|
|
|