2024-05-06 17:55:11 +00:00
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
2024-05-06 20:22:43 +00:00
import StatusQ . Core . Utils 0.1 as SQUtils
2024-05-06 17:55:11 +00:00
import Models 1.0
import Storybook 1.0
import AppLayouts . Wallet . controls 1.0
import AppLayouts . Wallet . services . dapps 1.0
import SortFilterProxyModel 0.2
import AppLayouts . Wallet . panels 1.0
2024-05-06 20:22:43 +00:00
import AppLayouts . Profile . stores 1.0
2024-05-06 17:55:11 +00:00
import utils 1.0
import shared . stores 1.0
Item {
id: root
// qml Splitter
SplitView {
anchors.fill: parent
ColumnLayout {
SplitView.fillWidth: true
Rectangle {
Layout.alignment: Qt . AlignCenter
Layout.preferredWidth: dappsWorkflow . implicitHeight + 20
Layout.preferredHeight: dappsWorkflow . implicitHeight + 20
border.color: "blue"
border.width: 1
DAppsWorkflow {
id: dappsWorkflow
anchors.centerIn: parent
spacing: 8
2024-05-06 20:22:43 +00:00
wcService: walletConnectService
2024-05-31 09:34:59 +00:00
onDisplayToastMessage: ( message , isErr ) = > {
if ( isErr ) {
console . log ( ` Storybook . displayToastMessage ( $ { message } , "" , "warning" , false , Constants . ephemeralNotificationType . danger , "" ) ` )
return
}
console . log ( ` Storybook . displayToastMessage ( $ { message } , "" , "checkmark-circle" , false , Constants . ephemeralNotificationType . success , "" ) ` )
}
2024-05-06 17:55:11 +00:00
}
}
ColumnLayout { }
}
ColumnLayout {
id: optionsSpace
RowLayout {
Text { text: "projectId" }
Text {
id: projectIdText
readonly property string projectId: SystemUtils . getEnvVar ( "WALLET_CONNECT_PROJECT_ID" )
2024-05-06 20:22:43 +00:00
text: SQUtils . Utils . elideText ( projectId , 3 )
2024-05-06 17:55:11 +00:00
font.bold: true
}
}
2024-05-06 20:22:43 +00:00
CheckBox {
text: "Testnet Mode"
checked: settings . testNetworks
onCheckedChanged: {
settings . testNetworks = checked
}
}
2024-05-06 17:55:11 +00:00
// spacer
ColumnLayout { }
2024-05-31 09:34:59 +00:00
CheckBox {
text: "Enable SDK"
checked: settings . enableSDK
onCheckedChanged: {
settings . enableSDK = checked
}
}
2024-05-06 17:55:11 +00:00
RowLayout {
Text { text: "URI" }
TextField {
id: pairUriInput
placeholderText: "Enter WC Pair URI"
text: settings . pairUri
onTextChanged: {
settings . pairUri = text
}
Layout.fillWidth: true
}
}
2024-05-21 10:42:50 +00:00
ComboBox {
model: [ { testCase: d . noTestCase , name: "No Test Case" } ,
{ testCase: d . openDappsTestCase , name: "Open dApps" } ,
{ testCase: d . openPairTestCase , name: "Open Pair" }
]
textRole: "name"
valueRole: "testCase"
currentIndex: settings . testCase
onCurrentValueChanged: {
settings . testCase = currentValue
if ( currentValue !== d . noTestCase ) {
d . startTestCase ( )
2024-05-06 17:55:11 +00:00
}
}
2024-05-06 20:22:43 +00:00
2024-05-06 17:55:11 +00:00
Connections {
target: dappsWorkflow
2024-05-06 20:22:43 +00:00
// If Open Pair workflow if selected in the side bar
2024-05-21 10:42:50 +00:00
function onDappsListReady ( ) {
if ( d . activeTestCase < d . openPairTestCase )
2024-05-06 17:55:11 +00:00
return
let items = InspectionUtils . findVisualsByTypeName ( dappsWorkflow , "DAppsListPopup" )
if ( items . length === 1 ) {
let buttons = InspectionUtils . findVisualsByTypeName ( items [ 0 ] , "StatusButton" )
if ( buttons . length === 1 ) {
buttons [ 0 ] . clicked ( )
}
}
}
2024-05-06 20:22:43 +00:00
function onPairWCReady ( ) {
2024-05-21 10:42:50 +00:00
if ( d . activeTestCase < d . openPairTestCase )
2024-05-06 17:55:11 +00:00
return
if ( pairUriInput . text . length > 0 ) {
let items = InspectionUtils . findVisualsByTypeName ( dappsWorkflow , "StatusBaseInput" )
if ( items . length === 1 ) {
items [ 0 ] . text = pairUriInput . text
2024-05-06 20:22:43 +00:00
clickDoneIfSDKReady ( )
2024-05-06 17:55:11 +00:00
}
}
2024-05-06 20:22:43 +00:00
}
function clickDoneIfSDKReady ( ) {
2024-05-21 10:42:50 +00:00
if ( d . activeTestCase < d . openPairTestCase ) {
2024-05-06 20:22:43 +00:00
return
}
let modals = InspectionUtils . findVisualsByTypeName ( dappsWorkflow , "PairWCModal" )
if ( modals . length === 1 ) {
let buttons = InspectionUtils . findVisualsByTypeName ( modals [ 0 ] . footer , "StatusButton" )
if ( buttons . length === 1 && walletConnectService . wcSDK . sdkReady ) {
2024-05-21 10:42:50 +00:00
d . activeTestCase = d . noTestCase
2024-05-06 20:22:43 +00:00
buttons [ 0 ] . clicked ( )
return
}
}
Backpressure . debounce ( dappsWorkflow , 250 , clickDoneIfSDKReady ) ( )
2024-05-06 17:55:11 +00:00
}
}
}
}
}
2024-05-06 20:22:43 +00:00
WalletConnectService {
id: walletConnectService
wcSDK: WalletConnectSDK {
2024-05-31 09:34:59 +00:00
active: settings . enableSDK
2024-05-06 17:55:11 +00:00
projectId: projectIdText . projectId
2024-05-06 20:22:43 +00:00
}
2024-05-20 18:42:31 +00:00
store: DAppsStore {
2024-05-21 10:42:50 +00:00
signal dappsListReceived ( string dappsJson )
2024-05-20 18:42:31 +00:00
function addWalletConnectSession ( sessionJson ) {
console . info ( "Persist Session" , sessionJson )
2024-05-21 10:42:50 +00:00
let session = JSON . parse ( sessionJson )
let firstIconUrl = session . peer . metadata . icons . length > 0 ? session . peer . metadata . icons [ 0 ] : ""
let persistedDapp = {
"name" : session . peer . metadata . name ,
"url" : session . peer . metadata . url ,
"iconUrl" : firstIconUrl
}
d . persistedDapps . push ( persistedDapp )
}
function getDapps ( ) {
this . dappsListReceived ( JSON . stringify ( d . persistedDapps ) )
return true
2024-05-20 18:42:31 +00:00
}
2024-05-06 20:22:43 +00:00
}
2024-05-06 17:55:11 +00:00
2024-05-06 20:22:43 +00:00
walletStore: WalletStore {
property var flatNetworks: SortFilterProxyModel {
sourceModel: NetworksModel . flatNetworks
filters: ValueFilter { roleName: "isTest" ; value: settings . testNetworks ; }
2024-05-06 17:55:11 +00:00
}
2024-05-06 20:22:43 +00:00
property var accounts: WalletAccountsModel { }
2024-05-06 17:55:11 +00:00
}
}
QtObject {
id: d
2024-05-21 10:42:50 +00:00
property int activeTestCase: noTestCase
2024-05-06 17:55:11 +00:00
2024-05-21 10:42:50 +00:00
function startTestCase ( ) {
d . activeTestCase = settings . testCase
2024-05-06 17:55:11 +00:00
if ( root . visible ) {
dappsWorkflow . clicked ( )
}
}
2024-05-21 10:42:50 +00:00
readonly property int noTestCase: 0
readonly property int openDappsTestCase: 1
readonly property int openPairTestCase: 2
property var persistedDapps: [
{ "name" : "Test dApp 1" , "url" : "https://dapp.test/1" , "iconUrl" : "https://se-sdk-dapp.vercel.app/assets/eip155:1.png" } ,
{ "name" : "Test dApp 2" , "url" : "https://dapp.test/2" , "iconUrl" : "https://react-app.walletconnect.com/assets/eip155-1.png" } ,
{ "name" : "Test dApp 3" , "url" : "https://dapp.test/3" , "iconUrl" : "https://react-app.walletconnect.com/assets/eip155-1.png" } ,
{ "name" : "Test dApp 4 - very long name !!!!!!!!!!!!!!!!" , "url" : "https://dapp.test/4" , "iconUrl" : "https://react-app.walletconnect.com/assets/eip155-1.png" } ,
{ "name" : "Test dApp 5 - very long url" , "url" : "https://dapp.test/very_long/url/unusual" , "iconUrl" : "https://react-app.walletconnect.com/assets/eip155-1.png" } ,
{ "name" : "Test dApp 6" , "url" : "https://dapp.test/6" , "iconUrl" : "https://react-app.walletconnect.com/assets/eip155-1.png" }
]
2024-05-06 17:55:11 +00:00
}
onVisibleChanged: {
2024-05-21 10:42:50 +00:00
if ( visible && d . activeTestCase !== d . noTestCase ) {
d . startTestCase ( )
2024-05-06 17:55:11 +00:00
}
}
Settings {
id: settings
2024-05-21 10:42:50 +00:00
property int testCase: d . noTestCase
2024-05-06 17:55:11 +00:00
property string pairUri: ""
2024-05-06 20:22:43 +00:00
property bool testNetworks: false
2024-05-31 09:34:59 +00:00
property bool enableSDK: true
2024-05-06 17:55:11 +00:00
}
}
// category: Wallet