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-08-02 11:18:58 +00:00
|
|
|
signal activeSessionsReceived(var activeSessionsJsonObj, bool success)
|
2024-07-17 10:46:43 +00:00
|
|
|
signal userAuthenticated(string topic, string id, string password, string pin, string payload)
|
2024-06-04 20:45:03 +00:00
|
|
|
signal userAuthenticationFailed(string topic, string id)
|
2024-05-20 18:42:31 +00:00
|
|
|
|
2024-08-09 14:00:28 +00:00
|
|
|
signal signingResult(string topic, string id, string data)
|
|
|
|
|
2024-11-18 13:20:10 +00:00
|
|
|
signal estimatedTimeResponse(string topic, int timeCategory, bool success)
|
|
|
|
signal suggestedFeesResponse(string topic, var suggestedFeesJsonObj, bool success)
|
|
|
|
signal estimatedGasResponse(string topic, string gasEstimate, bool success)
|
|
|
|
|
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-07-17 10:46:43 +00:00
|
|
|
function authenticateUser(topic, id, address, payload) {
|
|
|
|
let ok = controller.authenticateUser(topic, id, address, payload)
|
2024-06-04 20:45:03 +00:00
|
|
|
if(!ok) {
|
|
|
|
root.userAuthenticationFailed()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-09 14:00:28 +00:00
|
|
|
function signMessageUnsafe(topic, id, address, message, password, pin = "") {
|
|
|
|
controller.signMessageUnsafe(topic, id, address, message, password, pin)
|
2024-07-01 21:02:05 +00:00
|
|
|
}
|
|
|
|
|
2024-08-09 14:00:28 +00:00
|
|
|
function signMessage(topic, id, address, message, password, pin = "") {
|
|
|
|
controller.signMessage(topic, id, address, message, password, pin)
|
2024-06-07 16:54:19 +00:00
|
|
|
}
|
|
|
|
|
2024-08-09 14:00:28 +00:00
|
|
|
function safeSignTypedData(topic, id, address, typedDataJson, chainId, legacy, password, pin = "") {
|
|
|
|
controller.safeSignTypedData(topic, id, address, typedDataJson, chainId, legacy, password, pin)
|
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-07-17 16:36:32 +00:00
|
|
|
let tx = Object.assign({}, txObj)
|
|
|
|
if (txObj.gasLimit) {
|
|
|
|
tx.gasLimit = stripLeadingZeros(txObj.gasLimit)
|
|
|
|
}
|
|
|
|
if (txObj.gas) {
|
|
|
|
tx.gas = stripLeadingZeros(txObj.gas)
|
|
|
|
}
|
|
|
|
if (txObj.gasPrice) {
|
|
|
|
tx.gasPrice = stripLeadingZeros(txObj.gasPrice)
|
|
|
|
}
|
|
|
|
if (txObj.nonce) {
|
|
|
|
tx.nonce = stripLeadingZeros(txObj.nonce)
|
|
|
|
}
|
|
|
|
if (txObj.maxFeePerGas) {
|
|
|
|
tx.maxFeePerGas = stripLeadingZeros(txObj.maxFeePerGas)
|
|
|
|
}
|
|
|
|
if (txObj.maxPriorityFeePerGas) {
|
|
|
|
tx.maxPriorityFeePerGas = stripLeadingZeros(txObj.maxPriorityFeePerGas)
|
|
|
|
}
|
|
|
|
if (txObj.value) {
|
|
|
|
tx.value = stripLeadingZeros(txObj.value)
|
|
|
|
}
|
2024-06-27 14:19:28 +00:00
|
|
|
return tx
|
2024-06-23 08:27:29 +00:00
|
|
|
}
|
2024-07-09 17:49:00 +00:00
|
|
|
|
2024-07-10 13:58:42 +00:00
|
|
|
// Empty maxFeePerGas will fetch the current chain's maxFeePerGas
|
2024-07-09 17:49:00 +00:00
|
|
|
// Returns ui/imports/utils -> Constants.TransactionEstimatedTime values
|
2024-11-18 13:20:10 +00:00
|
|
|
function requestEstimatedTime(topic, chainId, maxFeePerGasHex) {
|
|
|
|
controller.requestEstimatedTime(topic, chainId, maxFeePerGasHex)
|
2024-07-09 17:49:00 +00:00
|
|
|
}
|
|
|
|
|
2024-07-17 10:46:43 +00:00
|
|
|
// Returns nim's SuggestedFeesDto; see src/app_service/service/transaction/dto.nim
|
|
|
|
// Returns all value initialized to 0 if error
|
2024-11-18 13:20:10 +00:00
|
|
|
function requestSuggestedFees(topic, chainId) {
|
|
|
|
controller.requestSuggestedFeesJson(topic, chainId)
|
|
|
|
}
|
|
|
|
|
|
|
|
function requestGasEstimate(topic, chainId, txObj) {
|
|
|
|
try {
|
|
|
|
let tx = prepareTxForStatusGo(txObj)
|
|
|
|
controller.requestGasEstimate(topic, chainId, JSON.stringify(tx))
|
|
|
|
} catch (e) {
|
|
|
|
console.error("Failed to prepare tx for status-go", e)
|
|
|
|
root.estimatedGasResponse(topic, "", false)
|
|
|
|
}
|
2024-07-17 10:46:43 +00:00
|
|
|
}
|
|
|
|
|
2024-06-23 08:27:29 +00:00
|
|
|
function signTransaction(topic, id, address, chainId, password, txObj) {
|
|
|
|
let tx = prepareTxForStatusGo(txObj)
|
2024-08-09 14:00:28 +00:00
|
|
|
controller.signTransaction(topic, id, address, chainId, JSON.stringify(tx), password, pin)
|
2024-06-18 19:45:56 +00:00
|
|
|
}
|
|
|
|
|
2024-08-09 14:00:28 +00:00
|
|
|
function sendTransaction(topic, id, address, chainId, txObj, password, pin = "") {
|
2024-06-23 08:27:29 +00:00
|
|
|
let tx = prepareTxForStatusGo(txObj)
|
2024-08-09 14:00:28 +00:00
|
|
|
controller.sendTransaction(topic, id, address, chainId, JSON.stringify(tx), password, pin)
|
2024-06-23 08:27:29 +00:00
|
|
|
}
|
|
|
|
|
2024-05-21 10:42:50 +00:00
|
|
|
/// \c getDapps triggers an async response to \c dappsListReceived
|
|
|
|
function getDapps() {
|
|
|
|
return controller.getDapps()
|
|
|
|
}
|
2024-08-02 11:18:58 +00:00
|
|
|
|
|
|
|
/// \c getActiveSessions triggers an async response to \c activeSessionsReceived
|
|
|
|
/// \returns true if the request was sent successfully
|
|
|
|
function getActiveSessions() {
|
|
|
|
return controller.getActiveSessions()
|
|
|
|
}
|
2024-05-21 10:42:50 +00:00
|
|
|
|
2024-07-17 10:46:43 +00:00
|
|
|
function hexToDec(hex) {
|
|
|
|
return controller.hexToDecBigString(hex)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return just the modified fields { "maxFeePerGas": "0x<...>", "maxPriorityFeePerGas": "0x<...>" }
|
|
|
|
function convertFeesInfoToHex(feesInfoJson) {
|
|
|
|
return controller.convertFeesInfoToHex(feesInfoJson)
|
|
|
|
}
|
|
|
|
|
2024-05-21 10:42:50 +00:00
|
|
|
// 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-08-02 11:18:58 +00:00
|
|
|
function onActiveSessionsReceived(activeSessionsJson) {
|
|
|
|
try {
|
|
|
|
const jsonObj = JSON.parse(activeSessionsJson)
|
|
|
|
root.activeSessionsReceived(jsonObj, true)
|
|
|
|
} catch (e) {
|
|
|
|
console.error("Failed to parse activeSessionsJson", e)
|
|
|
|
root.activeSessionsReceived({}, false)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-17 10:46:43 +00:00
|
|
|
function onUserAuthenticationResult(topic, id, success, password, pin, payload) {
|
2024-06-04 20:45:03 +00:00
|
|
|
if (success) {
|
2024-07-17 10:46:43 +00:00
|
|
|
root.userAuthenticated(topic, id, password, pin, payload)
|
2024-06-04 20:45:03 +00:00
|
|
|
} else {
|
|
|
|
root.userAuthenticationFailed(topic, id)
|
|
|
|
}
|
|
|
|
}
|
2024-08-09 14:00:28 +00:00
|
|
|
|
|
|
|
function onSigningResultReceived(topic, id, data) {
|
|
|
|
root.signingResult(topic, id, data)
|
|
|
|
}
|
2024-11-18 13:20:10 +00:00
|
|
|
|
|
|
|
function onEstimatedTimeResponse(topic, timeCategory) {
|
|
|
|
root.estimatedTimeResponse(topic, timeCategory, !!timeCategory)
|
|
|
|
}
|
|
|
|
|
|
|
|
function onSuggestedFeesResponse(topic, suggestedFeesJson) {
|
|
|
|
try {
|
|
|
|
const jsonObj = JSON.parse(suggestedFeesJson)
|
|
|
|
root.suggestedFeesResponse(topic, jsonObj, true)
|
|
|
|
} catch (e) {
|
|
|
|
console.error("Failed to parse suggestedFeesJson", e)
|
|
|
|
root.suggestedFeesResponse(topic, {}, false)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onEstimatedGasResponse(topic, gasEstimate) {
|
|
|
|
root.estimatedGasResponse(topic, gasEstimate, !!gasEstimate)
|
|
|
|
}
|
2024-05-20 18:42:31 +00:00
|
|
|
}
|
2024-08-09 14:00:28 +00:00
|
|
|
}
|