parent
3d408e4966
commit
b04c46d288
|
@ -107,8 +107,8 @@ QtObject:
|
|||
error "pairing", msg=error
|
||||
self.respondSessionProposal(sessionProposalJson, supportedNamespacesJson, error)
|
||||
|
||||
proc recordSuccessfulPairing(self: Controller, sessionProposalJson: string) {.slot.} =
|
||||
if backend_wallet_connect.recordSuccessfulPairing(sessionProposalJson):
|
||||
proc upsertSession(self: Controller, sessionJson: string) {.slot.} =
|
||||
if backend_wallet_connect.upsertSession(sessionJson):
|
||||
if not self.hasActivePairings.get(false):
|
||||
self.hasActivePairings = some(true)
|
||||
|
||||
|
|
|
@ -26,8 +26,8 @@ rpc(wCSendTransactionWithSignature, "wallet"):
|
|||
rpc(wCPairSessionProposal, "wallet"):
|
||||
sessionProposalJson: string
|
||||
|
||||
rpc(wCRecordSuccessfulPairing, "wallet"):
|
||||
sessionProposalJson: string
|
||||
rpc(wCUpsertSession, "wallet"):
|
||||
sessionJson: string
|
||||
|
||||
rpc(wCChangePairingState, "wallet"):
|
||||
topic: string
|
||||
|
@ -63,9 +63,9 @@ proc pair*(res: var JsonNode, sessionProposalJson: string): string =
|
|||
warn e.msg
|
||||
return e.msg
|
||||
|
||||
proc recordSuccessfulPairing*(sessionProposalJson: string): bool =
|
||||
proc upsertSession*(sessionJson: string): bool =
|
||||
try:
|
||||
let response = wCRecordSuccessfulPairing(sessionProposalJson)
|
||||
let response = wCUpsertSession(sessionJson)
|
||||
return not isErrorResponse(response)
|
||||
except Exception as e:
|
||||
warn e.msg
|
||||
|
|
|
@ -3,6 +3,7 @@ import QtQuick.Controls 2.15
|
|||
import QtQuick.Layouts 1.15
|
||||
import QtQml 2.15
|
||||
import Qt.labs.settings 1.0
|
||||
import QtWebEngine 1.10
|
||||
|
||||
import StatusQ.Core 0.1
|
||||
import StatusQ.Core.Utils 0.1
|
||||
|
@ -37,17 +38,17 @@ Item {
|
|||
respondSessionProposal(sessionProposalJson, `{"eip155":{"methods":["eth_sendTransaction","eth_sendRawTransaction","personal_sign","eth_sign","eth_signTransaction","eth_signTypedData","wallet_switchEthereumChain"],"chains":["eip155:5"],"events":["accountsChanged","chainChanged"],"accounts":["eip155:5:0xE2d622C817878dA5143bBE06866ca8E35273Ba8a"]}}`, "")
|
||||
}
|
||||
|
||||
recordSuccessfulPairing: function(sessionProposalJson) {
|
||||
const sessionProposal = JSON.parse(sessionProposalJson)
|
||||
upsertSession: function(sessionJson) {
|
||||
const session = JSON.parse(sessionJson)
|
||||
|
||||
pairingsModel.append({
|
||||
topic: sessionProposal.params.pairingTopic,
|
||||
expiry: sessionProposal.params.expiry,
|
||||
topic: session.topic,
|
||||
expiry: session.expiry,
|
||||
active: true,
|
||||
peerMetadata: {
|
||||
name: sessionProposal.params.proposer.metadata.name,
|
||||
url: sessionProposal.params.proposer.metadata.url,
|
||||
icons: sessionProposal.params.proposer.metadata.icons,
|
||||
name: session.peer.metadata.name,
|
||||
url: session.peer.metadata.url,
|
||||
icons: session.peer.metadata.icons,
|
||||
}
|
||||
})
|
||||
root.saveListModel(pairingsModel)
|
||||
|
@ -139,7 +140,7 @@ Item {
|
|||
Layout.maximumHeight: 300
|
||||
|
||||
onDisconnect: function(pairingTopic) {
|
||||
wc.sdk.disconnectPairing(pairingTopic)
|
||||
wc.sdk.disconnectTopic(pairingTopic)
|
||||
}
|
||||
|
||||
model: ListModel {
|
||||
|
@ -167,6 +168,23 @@ Item {
|
|||
|
||||
// spacer
|
||||
ColumnLayout {}
|
||||
StatusButton {
|
||||
text: "Clear SDK cache"
|
||||
|
||||
enabled: d.webEngine
|
||||
|
||||
onClicked: {
|
||||
SystemUtils.removeDir(d.webEngine.profile.persistentStoragePath)
|
||||
d.webEngine.reload()
|
||||
}
|
||||
}
|
||||
StatusCheckBox {
|
||||
id: autoOpenCheckBox
|
||||
|
||||
text: "Auto-open dialog"
|
||||
|
||||
checked: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,10 +195,14 @@ Item {
|
|||
|
||||
property bool hasActivePairings: hasActivePairingsCheckBox.checked
|
||||
property string pairingsHistory: ""
|
||||
property bool autoOpenModal: autoOpenCheckBox.checked
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
loadListModel(pairingsModel)
|
||||
|
||||
wc.modal.visible = settings.autoOpenModal
|
||||
autoOpenCheckBox.checked = settings.autoOpenModal
|
||||
}
|
||||
|
||||
function saveListModel(model) {
|
||||
|
@ -201,6 +223,23 @@ Item {
|
|||
pairingsModel.append(entry);
|
||||
});
|
||||
}
|
||||
|
||||
QtObject {
|
||||
id: d
|
||||
|
||||
property WebEngineView webEngine: null
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: wc.sdk.webEngineLoader
|
||||
function onEngineLoaded(instance) {
|
||||
d.webEngine = instance
|
||||
}
|
||||
|
||||
function onEngineUnloaded() {
|
||||
d.webEngine = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// category: Popups
|
||||
|
|
|
@ -9,8 +9,8 @@ Item {
|
|||
|
||||
// function sessionProposal(/*string*/ sessionProposalJson)
|
||||
required property var sessionProposal
|
||||
// function pairSessionRequest(/*string*/ sessionRequestJson)
|
||||
required property var recordSuccessfulPairing
|
||||
// function upsertSession(/*string*/ sessionRequestJson)
|
||||
required property var upsertSession
|
||||
// function deletePairing(/*string*/ topic)
|
||||
required property var deletePairing
|
||||
|
||||
|
|
|
@ -1,9 +1,46 @@
|
|||
#include "systemutils.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QDir>
|
||||
|
||||
SystemUtils::SystemUtils(QObject *parent) : QObject(parent) {}
|
||||
SystemUtils::SystemUtils(QObject* parent)
|
||||
: QObject(parent)
|
||||
{ }
|
||||
|
||||
QString SystemUtils::getEnvVar(const QString &varName) {
|
||||
QString SystemUtils::getEnvVar(const QString& varName)
|
||||
{
|
||||
return qEnvironmentVariable(varName.toUtf8().constData(), "");
|
||||
}
|
||||
|
||||
bool SystemUtils::removeDir(const QString& path)
|
||||
{
|
||||
QDir dir(path);
|
||||
|
||||
if(!dir.exists())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
dir.setFilter(QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs);
|
||||
QFileInfoList fileList = dir.entryInfoList();
|
||||
|
||||
foreach(const QFileInfo& fileInfo, fileList)
|
||||
{
|
||||
if(fileInfo.isDir())
|
||||
{
|
||||
if(!removeDir(fileInfo.absoluteFilePath()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!QFile::remove(fileInfo.absoluteFilePath()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dir.rmdir(path);
|
||||
}
|
|
@ -7,7 +7,8 @@ class SystemUtils : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SystemUtils(QObject *parent = nullptr);
|
||||
explicit SystemUtils(QObject* parent = nullptr);
|
||||
|
||||
Q_INVOKABLE QString getEnvVar(const QString &varName);
|
||||
Q_INVOKABLE QString getEnvVar(const QString& varName);
|
||||
Q_INVOKABLE bool removeDir(const QString& path);
|
||||
};
|
||||
|
|
|
@ -272,7 +272,7 @@
|
|||
acceptPairButton.remove();
|
||||
rejectPairButton.remove();
|
||||
|
||||
root.controller_recordSuccessfulPairing(JSON.stringify(sessionProposal));
|
||||
root.controller_upsertSession(JSON.stringify(sessionProposal));
|
||||
|
||||
logComponentStatusChange(
|
||||
"GO.pairSessionProposal",
|
||||
|
|
|
@ -168,9 +168,9 @@ func main() {
|
|||
}
|
||||
|
||||
func mockController(w webview.WebView) {
|
||||
w.Bind("controller_recordSuccessfulPairing", func(sessionProposalJson string) {
|
||||
fmt.Println("controller_recordSuccessfulPairing:", sessionProposalJson)
|
||||
sessionProposalRes := callPrivateMethod("wallet_wCRecordSuccessfulPairing", []interface{}{sessionProposalJson})
|
||||
w.Bind("controller_upsertSession", func(sessionProposalJson string) {
|
||||
fmt.Println("controller_upsertSession:", sessionProposalJson)
|
||||
sessionProposalRes := callPrivateMethod("wallet_wCUpsertSession", []interface{}{sessionProposalJson})
|
||||
var apiResponse wc.PairSessionResponse
|
||||
err := getRPCAPIResponse(sessionProposalRes, &apiResponse)
|
||||
if err != nil {
|
||||
|
|
|
@ -45,6 +45,8 @@ Item {
|
|||
|
||||
visible: false
|
||||
|
||||
profile.storageName: "WC"
|
||||
|
||||
url: root.url
|
||||
webChannel: statusChannel
|
||||
|
||||
|
|
|
@ -299,12 +299,12 @@ Popup {
|
|||
root.state = d.waitingUserResponseToSessionRequest
|
||||
}
|
||||
|
||||
function onApproveSessionResult(sessionProposal, error) {
|
||||
function onApproveSessionResult(session, error) {
|
||||
d.setDetailsText("")
|
||||
if (!error) {
|
||||
d.setStatusText("Pairing OK")
|
||||
d.state = d.pairedState
|
||||
root.controller.recordSuccessfulPairing(JSON.stringify(sessionProposal))
|
||||
root.controller.upsertSession(JSON.stringify(session))
|
||||
} else {
|
||||
d.setStatusText("Pairing error", "red")
|
||||
d.state = ""
|
||||
|
|
|
@ -29,7 +29,7 @@ Item {
|
|||
signal sdkInit(bool success, var result)
|
||||
signal sessionProposal(var sessionProposal)
|
||||
signal sessionProposalExpired()
|
||||
signal approveSessionResult(var sessionProposal, string error)
|
||||
signal approveSessionResult(var session, string error)
|
||||
signal rejectSessionResult(string error)
|
||||
signal sessionRequestEvent(var sessionRequest)
|
||||
signal sessionRequestUserAnswerResult(bool accept, string error)
|
||||
|
@ -212,11 +212,11 @@ Item {
|
|||
|
||||
d.engine.runJavaScript(`
|
||||
wc.approveSession(${JSON.stringify(sessionProposal)}, ${JSON.stringify(supportedNamespaces)})
|
||||
.then((value) => {
|
||||
wc.statusObject.onApproveSessionResponse(${JSON.stringify(sessionProposal)}, "")
|
||||
.then((session) => {
|
||||
wc.statusObject.onApproveSessionResponse(session, ${JSON.stringify(sessionProposal)}, "")
|
||||
})
|
||||
.catch((e) => {
|
||||
wc.statusObject.onApproveSessionResponse(${JSON.stringify(sessionProposal)}, e.message)
|
||||
wc.statusObject.onApproveSessionResponse('', ${JSON.stringify(sessionProposal)}, e.message)
|
||||
})
|
||||
`
|
||||
)
|
||||
|
@ -390,16 +390,12 @@ Item {
|
|||
d.resetSessionsModel()
|
||||
}
|
||||
|
||||
function onApproveSessionResponse(sessionProposal, error) {
|
||||
console.debug(`WC WalletConnectSDK.onApproveSessionResponse; sessionProposal: ${JSON.stringify(sessionProposal, null, 2)}, error: ${error}`)
|
||||
function onApproveSessionResponse(session, error) {
|
||||
console.debug(`WC WalletConnectSDK.onApproveSessionResponse; session: ${JSON.stringify(session, null, 2)}; error: ${error}`)
|
||||
|
||||
// Update the temporary expiry with the one from the pairing
|
||||
d.resetPairingsModel((pairing) => {
|
||||
if (pairing.topic === sessionProposal.params.pairingTopic) {
|
||||
sessionProposal.params.expiry = pairing.expiry
|
||||
root.approveSessionResult(sessionProposal, error)
|
||||
}
|
||||
})
|
||||
root.approveSessionResult(session, error)
|
||||
|
||||
d.resetPairingsModel()
|
||||
d.resetSessionsModel()
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -129,7 +129,7 @@ window.wc = {
|
|||
await window.wc.web3wallet.engine.signClient.ping({ topic });
|
||||
},
|
||||
|
||||
approveSession: async function (sessionProposal, supportedNamespaces) {
|
||||
approveSession: function (sessionProposal, supportedNamespaces) {
|
||||
const { id, params } = sessionProposal;
|
||||
|
||||
const { relays } = params
|
||||
|
@ -141,7 +141,7 @@ window.wc = {
|
|||
}
|
||||
);
|
||||
|
||||
await window.wc.web3wallet.approveSession(
|
||||
return window.wc.web3wallet.approveSession(
|
||||
{
|
||||
id,
|
||||
relayProtocol: relays[0].protocol,
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit b52a9ce0e5f72e62086f84a6a639a6de0bfd5c7e
|
||||
Subproject commit 9d4e3aa36e248dfb5d12352276d101110fdc0213
|
Loading…
Reference in New Issue