2024-05-01 16:15:42 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
|
2024-05-31 09:58:47 +00:00
|
|
|
import StatusQ.Core.Utils 0.1
|
|
|
|
|
|
|
|
QObject {
|
2024-05-21 10:42:50 +00:00
|
|
|
id: root
|
|
|
|
|
|
|
|
required property var controller
|
|
|
|
|
|
|
|
/// \c dappsJson serialized from status-go.wallet.GetDapps
|
|
|
|
signal dappsListReceived(string dappsJson)
|
2024-06-07 16:54:19 +00:00
|
|
|
signal userAuthenticated(string topic, string id, string password, string pin)
|
2024-06-04 20:45:03 +00:00
|
|
|
signal userAuthenticationFailed(string topic, string id)
|
2024-05-20 18:42:31 +00:00
|
|
|
|
|
|
|
function addWalletConnectSession(sessionJson) {
|
2024-06-07 16:54:19 +00:00
|
|
|
return controller.addWalletConnectSession(sessionJson)
|
2024-05-21 10:42:50 +00:00
|
|
|
}
|
|
|
|
|
2024-06-24 21:26:53 +00:00
|
|
|
function deactivateWalletConnectSession(topic) {
|
|
|
|
return controller.deactivateWalletConnectSession(topic)
|
|
|
|
}
|
|
|
|
|
2024-06-27 14:15:17 +00:00
|
|
|
function updateWalletConnectSessions(activeTopicsJson) {
|
|
|
|
return controller.updateSessionsMarkedAsActive(activeTopicsJson)
|
|
|
|
}
|
|
|
|
|
2024-06-04 20:45:03 +00:00
|
|
|
function authenticateUser(topic, id, address) {
|
|
|
|
let ok = controller.authenticateUser(topic, id, address)
|
|
|
|
if(!ok) {
|
|
|
|
root.userAuthenticationFailed()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-07 16:54:19 +00:00
|
|
|
// Returns the hex encoded signature of the message or empty string if error
|
|
|
|
function signMessage(topic, id, address, password, message) {
|
|
|
|
return controller.signMessage(address, password, message)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the hex encoded signature of the typedDataJson or empty string if error
|
|
|
|
function signTypedDataV4(topic, id, address, password, typedDataJson) {
|
|
|
|
return controller.signTypedDataV4(address, password, typedDataJson)
|
2024-06-04 20:45:03 +00:00
|
|
|
}
|
|
|
|
|
2024-06-18 19:45:56 +00:00
|
|
|
// Remove leading zeros from hex number as expected by status-go
|
|
|
|
function stripLeadingZeros(hexNumber) {
|
|
|
|
let fixed = hexNumber.replace(/^0x0*/, '0x')
|
|
|
|
return fixed == '0x' ? '0x0' : fixed;
|
|
|
|
}
|
|
|
|
|
2024-06-23 08:27:29 +00:00
|
|
|
// Strip leading zeros from numbers as expected by status-go
|
|
|
|
function prepareTxForStatusGo(txObj) {
|
2024-06-27 14:19:28 +00:00
|
|
|
let tx = {}
|
|
|
|
if (txObj.data) { tx.data = txObj.data }
|
|
|
|
if (txObj.from) { tx.from = txObj.from }
|
|
|
|
if (txObj.gasLimit) { tx.gasLimit = stripLeadingZeros(txObj.gasLimit) }
|
|
|
|
if (txObj.gasPrice) { tx.gasPrice = stripLeadingZeros(txObj.gasPrice) }
|
|
|
|
if (txObj.nonce) { tx.nonce = stripLeadingZeros(txObj.nonce) }
|
|
|
|
if (txObj.to) { tx.to = txObj.to }
|
|
|
|
if (txObj.value) { tx.value = stripLeadingZeros(txObj.value) }
|
|
|
|
return tx
|
2024-06-23 08:27:29 +00:00
|
|
|
}
|
|
|
|
// Returns the hex encoded signature of the transaction or empty string if error
|
|
|
|
function signTransaction(topic, id, address, chainId, password, txObj) {
|
|
|
|
let tx = prepareTxForStatusGo(txObj)
|
2024-06-18 19:45:56 +00:00
|
|
|
return controller.signTransaction(address, chainId, password, JSON.stringify(tx))
|
|
|
|
}
|
|
|
|
|
2024-06-23 08:27:29 +00:00
|
|
|
// Returns the hash of the transaction or empty string if error
|
|
|
|
function sendTransaction(topic, id, address, chainId, password, txObj) {
|
|
|
|
let tx = prepareTxForStatusGo(txObj)
|
|
|
|
return controller.sendTransaction(address, chainId, password, JSON.stringify(tx))
|
|
|
|
}
|
|
|
|
|
2024-05-21 10:42:50 +00:00
|
|
|
/// \c getDapps triggers an async response to \c dappsListReceived
|
|
|
|
function getDapps() {
|
|
|
|
return controller.getDapps()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle async response from controller
|
2024-05-31 09:58:47 +00:00
|
|
|
Connections {
|
2024-05-21 10:42:50 +00:00
|
|
|
target: controller
|
|
|
|
|
|
|
|
function onDappsListReceived(dappsJson) {
|
|
|
|
root.dappsListReceived(dappsJson)
|
|
|
|
}
|
2024-06-04 20:45:03 +00:00
|
|
|
|
2024-06-07 16:54:19 +00:00
|
|
|
function onUserAuthenticationResult(topic, id, success, password, pin) {
|
2024-06-04 20:45:03 +00:00
|
|
|
if (success) {
|
2024-06-07 16:54:19 +00:00
|
|
|
root.userAuthenticated(topic, id, password, pin)
|
2024-06-04 20:45:03 +00:00
|
|
|
} else {
|
|
|
|
root.userAuthenticationFailed(topic, id)
|
|
|
|
}
|
|
|
|
}
|
2024-05-20 18:42:31 +00:00
|
|
|
}
|
|
|
|
}
|