Fix: inject token data into action view is broken

pull/1649/head
Hwee-Boon Yar 5 years ago
parent c0b06c2be7
commit 0165a46a59
  1. 1
      AlphaWallet/Tokens/ViewControllers/TokenInstanceActionViewController.swift
  2. 13
      AlphaWallet/Tokens/Views/TokenInstanceWebView.swift

@ -25,6 +25,7 @@ class TokenInstanceActionViewController: UIViewController, TokenVerifiableStatus
let webView = TokenInstanceWebView(server: server, walletAddress: walletAddress, assetDefinitionStore: assetDefinitionStore)
webView.isWebViewInteractionEnabled = true
webView.delegate = self
webView.isStandalone = true
return webView
}()

@ -37,6 +37,11 @@ class TokenInstanceWebView: UIView {
}
weak var delegate: TokenInstanceWebViewDelegate?
var shouldOnlyRenderIfHeightIsCached = false
//HACK: Flag necessary to inject token values somewhat reliably in at least 2 distinct cases:
//A. TokenScript views in token cards (ie. view iconified)
//B. Action views
//TODO improve further. It's not reliable enough
var isStandalone = false
init(server: RPCServer, walletAddress: AlphaWallet.Address, assetDefinitionStore: AssetDefinitionStore) {
self.server = server
@ -117,8 +122,12 @@ class TokenInstanceWebView: UIView {
const oldTokens = web3.tokens.data
""" + string
//Important to inject JavaScript differently depending on whether this is the first time it's loaded because the HTML document may not be ready yet. Seems like it is necessary for `afterDocumentIsLoaded` to always be true here in order to avoid `Can't find variable: web3` errors
inject(javaScript: javaScript, afterDocumentIsLoaded: true)
//Important to inject JavaScript differently depending on whether this is the first time it's loaded because the HTML document may not be ready yet. Seems like it is necessary for `afterDocumentIsLoaded` to always be true here in order to avoid `Can't find variable: web3` errors when used for token cards
if isStandalone {
inject(javaScript: javaScript, afterDocumentIsLoaded: isFirstUpdate)
} else {
inject(javaScript: javaScript, afterDocumentIsLoaded: true)
}
}
private func implicitAttributes(tokenHolder: TokenHolder, isFungible: Bool) -> [String: AssetInternalValue] {

Loading…
Cancel
Save