Skip to content

Commit

Permalink
draft: Remove the business logic from UI components
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjba committed Oct 3, 2024
1 parent 9acf8d8 commit 0a26f8d
Show file tree
Hide file tree
Showing 21 changed files with 812 additions and 497 deletions.
53 changes: 48 additions & 5 deletions storybook/pages/DAppsWorkflowPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,42 @@ Item {

spacing: 8

wcService: walletConnectService
readonly property var wcService: walletConnectService
loginType: Constants.LoginType.Biometrics
selectedAccountAddress: ""

model: wcService.dappsModel
accountsModel: wcService.validAccounts
networksModel: wcService.flatNetworks
sessionRequestsModel: wcService.sessionRequestsModel

//formatBigNumber: (number, symbol, noSymbolOption) => wcService.walletRootStore.currencyStore.formatBigNumber(number, symbol, noSymbolOption)

onDisconnectRequested: (connectionId) => wcService.disconnectDapp(connectionId)
onPairingRequested: (uri) => wcService.pair(uri)
onPairingValidationRequested: (uri) => wcService.validatePairingUri(uri)
onConnectionAccepted: (pairingId, chainIds, selectedAccount) => wcService.approvePairSession(pairingId, chainIds, selectedAccount)
onConnectionDeclined: (pairingId) => wcService.rejectPairSession(pairingId)
onSignRequestAccepted: (connectionId, requestId) => wcService.sign(connectionId, requestId)
onSignRequestRejected: (connectionId, requestId) => wcService.rejectSign(connectionId, requestId, false /*hasError*/)

Connections {
target: dappsWorkflow.wcService
function onPairingValidated(validationState) {
dappsWorkflow.pairingValidated(validationState)
}
function onApproveSessionResult(pairingId, err, newConnectionId) {
if (err) {
dappsWorkflow.connectionFailed(pairingId)
return
}

dappsWorkflow.connectionSuccessful(pairingId, newConnectionId)
}
function onConnectDApp(dappChains, dappUrl, dappName, dappIcon, pairingId) {
dappsWorkflow.connectDApp(dappChains, dappUrl, dappName, dappIcon, pairingId)
}
}
}
}
ColumnLayout {}
Expand Down Expand Up @@ -128,7 +161,7 @@ Item {
ListView {
Layout.fillWidth: true
Layout.preferredHeight: Math.min(50, contentHeight)
model: walletConnectService.requestHandler.requestsModel
model: walletConnectService.sessionRequestsModel
delegate: RowLayout {
StatusBaseText {
text: SQUtils.Utils.elideAndFormatWalletAddress(model.topic, 6, 4)
Expand Down Expand Up @@ -308,15 +341,25 @@ Item {
signal userAuthenticated(string topic, string id, string password, string pin)
signal userAuthenticationFailed(string topic, string id)
signal signingResult(string topic, string id, string data)
signal activeSessionsReceived(var activeSessionsJsonObj, bool success)

function addWalletConnectSession(sessionJson) {
console.info("Persist Session", sessionJson)

console.info("Add Persisted Session", sessionJson)
let session = JSON.parse(sessionJson)
d.updateSessionsModelAndAddNewIfNotNull(session)

return true
}

function getActiveSessions() {
console.info("Get Active Sessions")
let sessions = JSON.parse(settings.persistedSessions)
let response = sessions.map(function(session) {
return {
sessionJson: JSON.stringify(session),
}
})
activeSessionsReceived(response, true)
}

function deactivateWalletConnectSession(topic) {
console.info("Deactivate Persisted Session", topic)
Expand Down
12 changes: 12 additions & 0 deletions ui/StatusQ/src/StatusQ/Core/Utils/ModelUtils.qml
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,16 @@ QtObject {

return null
}

function forEach(model, callback) {
if (!model)
return

const count = model.rowCount()

for (let i = 0; i < count; i++) {
const modelItem = Internal.ModelUtils.get(model, i)
callback(modelItem)
}
}
}
Loading

0 comments on commit 0a26f8d

Please sign in to comment.