[#5623] Bancor: "Oh, no..." error if try to buy token for ETH (or SNT)

Signed-off-by: Igor Mandrigin <i@mandrigin.ru>
This commit is contained in:
Andrey Shovkoplyas 2018-08-24 12:58:13 +03:00 committed by Igor Mandrigin
parent 172d63af4c
commit 11199c13ee
No known key found for this signature in database
GPG Key ID: 4A0EDDE26E66BC8B
4 changed files with 45 additions and 12 deletions

View File

@ -2,6 +2,10 @@ if(typeof StatusHttpProvider === "undefined"){
var callbackId = 0;
var callbacks = {};
function bridgeSend(data){
WebViewBridge.send(JSON.stringify(data));
}
WebViewBridge.onMessage = function (message) {
data = JSON.parse(message);
@ -24,8 +28,18 @@ WebViewBridge.onMessage = function (message) {
else if (data.type === "web3-send-async-callback")
{
var id = data.messageId;
if (callbacks[id]) {
callbacks[id](data.error, data.result);
var callback = callbacks[id];
if (callback) {
if (callback.results)
{
callback.results.push(data.error || data.result);
if (callback.results.length == callback.num)
callback.callback(undefined, callback.results);
}
else
{
callback.callback(data.error, data.result);
}
}
}
};
@ -76,10 +90,26 @@ StatusHttpProvider.prototype.sendAsync = function (payload, callback) {
}
else {
var messageId = callbackId++;
callbacks[messageId] = callback;
WebViewBridge.send(JSON.stringify({type: 'web3-send-async',
messageId: messageId,
payload: payload}));
if (Array.isArray(payload))
{
callbacks[messageId] = {num: payload.length,
results: [],
callback: callback};
for (var i in payload) {
bridgeSend({type: 'web3-send-async',
messageId: messageId,
payload: payload[i]});
}
}
else
{
callbacks[messageId] = {callback: callback};
bridgeSend({type: 'web3-send-async',
messageId: messageId,
payload: payload});
}
}
};
}

View File

@ -128,7 +128,10 @@
(defn discard-transaction
[{:keys [db]}]
(let [{:keys [dapp-transaction]} (get-in db [:wallet :send-transaction])]
(cond-> {:db (assoc-in db [:wallet :send-transaction] {})}
(cond-> {:db (update db :wallet
assoc
:send-transaction {}
:transactions-queue nil)}
dapp-transaction
(web3-error-callback db dapp-transaction "discarded"))))

View File

@ -12,7 +12,7 @@
(spec/def ::gas-price (spec/nilable money/valid?))
; dapp transaction
(spec/def ::data (spec/nilable string?))
(spec/def ::nonce (spec/nilable money/valid?))
(spec/def ::nonce (spec/nilable string?))
(spec/def ::to-name (spec/nilable string?))
(spec/def ::amount-error (spec/nilable string?))
@ -36,7 +36,7 @@
(spec/def :wallet/send-transaction (allowed-keys
:opt-un [::amount ::to ::to-name ::amount-error ::asset-error ::amount-text
::password ::show-password-input? ::id ::from ::data
::password ::show-password-input? ::id ::from ::data ::nonce
::camera-flashlight ::in-progress? ::dapp-transaction
::wrong-password? ::from-chat? ::symbol ::advanced?
::gas ::gas-price ::whisper-identity ::method ::tx-hash]))

View File

@ -125,14 +125,14 @@
;;SEND TRANSACTION
(= method constants/web3-send-transaction)
(let [{:keys [gas gasPrice] :as transaction} (models.wallet/prepare-dapp-transaction
queued-transaction (:contacts/contacts db))
(let [{:keys [gas gas-price] :as transaction} (models.wallet/prepare-dapp-transaction
queued-transaction (:contacts/contacts db))
{:keys [wallet-set-up-passed?]} (:account/account db)]
{:db (assoc-in db' [:wallet :send-transaction] transaction)
:dispatch-n [[:update-wallet]
(when-not gas
[:wallet/update-estimated-gas (first params)])
(when-not gasPrice
(when-not gas-price
[:wallet/update-gas-price])
[:navigate-to-modal (if wallet-set-up-passed?
:wallet-send-transaction-modal