-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dapps) add DAppsService component and ConnectDAppModal
Also rename pairing modal accordingly to make room for the proper ConnectDAppModal.qml Closes #14607
- Loading branch information
1 parent
ad2aaa7
commit 8e79216
Showing
19 changed files
with
2,238 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import QtQuick 2.15 | ||
import QtQuick.Controls 2.15 | ||
import QtQuick.Layouts 1.15 | ||
import QtQml 2.15 | ||
import Qt.labs.settings 1.0 | ||
import QtTest 1.15 | ||
|
||
import StatusQ.Core 0.1 | ||
import StatusQ.Core.Utils 0.1 | ||
import StatusQ.Controls 0.1 | ||
import StatusQ.Components 0.1 | ||
import StatusQ.Core.Theme 0.1 | ||
import StatusQ.Popups.Dialog 0.1 | ||
|
||
import Models 1.0 | ||
import Storybook 1.0 | ||
|
||
import shared.popups.walletconnect 1.0 | ||
|
||
import SortFilterProxyModel 0.2 | ||
|
||
import AppLayouts.Wallet.panels 1.0 | ||
|
||
import utils 1.0 | ||
import shared.stores 1.0 | ||
|
||
Item { | ||
id: root | ||
|
||
function openModal() { | ||
modal.openWithFilter([], [], JSON.parse(`{ | ||
"metadata": { | ||
"description": "React App for WalletConnect", | ||
"icons": [ | ||
"https://avatars.githubusercontent.com/u/37784886" | ||
], | ||
"name": "React App", | ||
"url": "https://react-app.walletconnect.com", | ||
"verifyUrl": "https://verify.walletconnect.com" | ||
}, | ||
"publicKey": "300a6a1df4cb0cd73eb652f11845f35a318541eb18ab369860be85c0c2ada54a" | ||
}`)) | ||
} | ||
|
||
// qml Splitter | ||
SplitView { | ||
anchors.fill: parent | ||
|
||
ColumnLayout { | ||
SplitView.fillWidth: true | ||
|
||
Component.onCompleted: root.openModal() | ||
|
||
StatusButton { | ||
id: openButton | ||
|
||
Layout.alignment: Qt.AlignHCenter | ||
Layout.margins: 20 | ||
|
||
text: "Open ConnectDAppModal" | ||
|
||
onClicked: root.openModal() | ||
} | ||
|
||
ConnectDAppModal { | ||
id: modal | ||
|
||
anchors.centerIn: parent | ||
|
||
spacing: 8 | ||
} | ||
|
||
ColumnLayout {} | ||
} | ||
|
||
ColumnLayout { | ||
id: optionsSpace | ||
} | ||
} | ||
} | ||
|
||
// category: Wallet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
import QtQuick 2.15 | ||
|
||
import AppLayouts.Wallet.services.dapps 1.0 | ||
|
||
QtObject { | ||
id: root | ||
|
||
required property WalletConnectSDK wCSDK | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
ui/app/AppLayouts/Wallet/services/dapps/WalletConnectService.qml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import QtQuick 2.15 | ||
|
||
import AppLayouts.Wallet.services.dapps 1.0 | ||
import AppLayouts.Profile.stores 1.0 | ||
import shared.stores 1.0 | ||
import shared.popups.walletconnect 1.0 | ||
|
||
QtObject { | ||
id: root | ||
|
||
required property WalletConnectSDK wcSDK | ||
required property DAppsStore dappsStore | ||
//required property WalletStore walletStore | ||
|
||
function pair(uri) { | ||
wcSDK.pair(uri) | ||
} | ||
|
||
/// proposer taken from the SessionProposal.params.proposer | ||
signal connectDApp(var chains, var accounts, var proposer) | ||
|
||
readonly property Connections sdkConnections: Connections { | ||
target: wcSDK | ||
function onPairResponse(success) { | ||
// TODO #14607: propagate pairings if the session is expired and report as error to the PairWCModal | ||
} | ||
|
||
function onSessionProposal(sessionProposal) { | ||
// TODO DEV: get the available chains and accounts from the source | ||
_d.currentSessionProposal = sessionProposal | ||
wcSDK.buildApprovedNamespaces(sessionProposal.params, JSON.parse(`{ | ||
"eip155": { | ||
"chains": ["eip155:11155111", "eip155:421614", "eip155:11155420"], | ||
"methods": ["eth_sendTransaction", "personal_sign"], | ||
"events": ["accountsChanged", "chainChanged"], | ||
"accounts": [ | ||
"eip155:11155111:0xE2D622C817878DA5143BBE06866CA8E35273BA8A", | ||
"eip155:421614:0xE2D622C817878DA5143BBE06866CA8E35273BA8A", | ||
"eip155:11155420:0xE2D622C817878DA5143BBE06866CA8E35273BA8A", | ||
"eip155:11155111:0xBD54A96C0AE19A220C8E1234F54C940DFAB34639", | ||
"eip155:421614:0xBD54A96C0AE19A220C8E1234F54C940DFAB34639", | ||
"eip155:11155420:0xBD54A96C0AE19A220C8E1234F54C940DFAB34639", | ||
"eip155:11155111:0x5D7905390B77A937AE8C444AA8BF7FA9A6A7DBA0", | ||
"eip155:421614:0x5D7905390B77A937AE8C444AA8BF7FA9A6A7DBA0", | ||
"eip155:11155420:0x5D7905390B77A937AE8C444AA8BF7FA9A6A7DBA0" | ||
] | ||
} | ||
}`)) | ||
} | ||
|
||
function onBuildApprovedNamespacesResult(approvedNamespaces, error) { | ||
if(error) { | ||
// TODO: error reporting | ||
return | ||
} | ||
|
||
let res = _d.extractChainsAndAccountsFromApprovedNamespaces(approvedNamespaces) | ||
|
||
root.connectDApp(res.chains, res.accounts, _d.currentSessionProposal.params.proposer) | ||
} | ||
} | ||
|
||
readonly property QtObject _d: QtObject { | ||
property var currentSessionProposal: null | ||
function extractChainsAndAccountsFromApprovedNamespaces(approvedNamespaces) { | ||
const eip155Data = approvedNamespaces.eip155; | ||
const chains = eip155Data.chains.map(chain => parseInt(chain.split(':').pop().trim(), 10)); | ||
const accountSet = new Set( | ||
eip155Data.accounts.map(account => account.split(':').pop().trim()) | ||
); | ||
const uniqueAccounts = Array.from(accountSet); | ||
return { chains, accounts: uniqueAccounts }; | ||
} | ||
} | ||
} |
Oops, something went wrong.