mirror of
https://github.com/lil-org/tokenary.git
synced 2024-11-22 21:49:51 +03:00
resolve rpc responses back inpage
This commit is contained in:
parent
517adbeb82
commit
280590ad6f
@ -199,16 +199,9 @@ class TokenaryEthereum extends EventEmitter {
|
||||
case "eth_newPendingTransactionFilter":
|
||||
case "eth_uninstallFilter":
|
||||
case "eth_subscribe":
|
||||
throw new ProviderRpcError(4200, `Tokenary does not support calling ${payload.method}. Please use your own solution`);
|
||||
throw new ProviderRpcError(4200, `tiny wallet does not support ${payload.method}`);
|
||||
default:
|
||||
this.callbacks.delete(payload.id);
|
||||
this.wrapResults.delete(payload.id);
|
||||
return this.rpc
|
||||
.call(payload)
|
||||
.then((response) => {
|
||||
wrapResult ? resolve(response) : resolve(response.result);
|
||||
})
|
||||
.catch(reject);
|
||||
return this.rpc.call(payload);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -394,13 +387,13 @@ class TokenaryEthereum extends EventEmitter {
|
||||
let callback = this.callbacks.get(id);
|
||||
let wrapResult = this.wrapResults.get(id);
|
||||
let data = { jsonrpc: "2.0", id: originId };
|
||||
if (result !== null && result.jsonrpc && result.result) {
|
||||
if (result !== null && result.result) {
|
||||
data.result = result.result;
|
||||
} else {
|
||||
data.result = result;
|
||||
}
|
||||
if (callback) {
|
||||
wrapResult ? callback(null, data) : callback(null, result);
|
||||
wrapResult ? callback(null, data) : callback(null, data.result);
|
||||
this.callbacks.delete(id);
|
||||
} else {
|
||||
console.log(`callback id: ${id} not found`);
|
||||
|
@ -45,7 +45,10 @@ announceProvider();
|
||||
|
||||
window.addEventListener("message", function(event) {
|
||||
if (event.source == window && event.data && event.data.direction == "rpc-back") {
|
||||
console.log("got it back inpage", event.data); // TODO: respond via rpc server
|
||||
// TODO: check event.data.response is there
|
||||
// TODO: make sure error is delivered as well
|
||||
console.log("rpc back", event.data.response);
|
||||
provider.sendResponse(event.data.response.id, event.data.response);
|
||||
} else if (event.source == window && event.data && event.data.direction == "from-content-script") {
|
||||
const response = event.data.response;
|
||||
const id = event.data.id;
|
||||
|
@ -10,6 +10,7 @@ class RPCServer {
|
||||
}
|
||||
|
||||
call(payload) {
|
||||
payload.jsonrpc = "2.0";
|
||||
window.postMessage({direction: "rpc", message: {id: payload.id, subject: "rpc", chainId: this.chainId, body: JSON.stringify(payload)}}, "*");
|
||||
return true;
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -82,6 +82,7 @@ class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
|
||||
let task = URLSession.shared.dataTask(with: request) { [weak self] data, response, error in
|
||||
if let data = data, let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
|
||||
self?.respond(with: json, context: context)
|
||||
// TODO: id is missing when there is an error
|
||||
} else {
|
||||
// TODO: respond with error
|
||||
self?.respond(with: ["yo": "body", "chainId": chainId, "result": "gg"], context: context)
|
||||
|
@ -8,5 +8,7 @@
|
||||
<array>
|
||||
<string>group.io.tokenary</string>
|
||||
</array>
|
||||
<key>com.apple.security.network.client</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
Loading…
Reference in New Issue
Block a user