Skip to content

Commit

Permalink
feat: Payment Request modal (#16744)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuteivist authored Dec 4, 2024
1 parent 387eab4 commit 5bf4ba2
Show file tree
Hide file tree
Showing 18 changed files with 882 additions and 13 deletions.
9 changes: 9 additions & 0 deletions src/app/global/feature_flags.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const DEFAULT_FLAG_DAPPS_ENABLED = true
const DEFAULT_FLAG_SWAP_ENABLED = true
const DEFAULT_FLAG_CONNECTOR_ENABLED* = true
const DEFAULT_FLAG_SEND_VIA_PERSONAL_CHAT_ENABLED = true
const DEFAULT_FLAG_PAYMENT_REQUEST_ENABLED = true

proc boolToEnv*(defaultValue: bool): string =
return if defaultValue: "1" else: "0"
Expand All @@ -15,13 +16,15 @@ QtObject:
swapEnabled: bool
connectorEnabled: bool
sendViaPersonalChatEnabled: bool
paymentRequestEnabled: bool

proc setup(self: FeatureFlags) =
self.QObject.setup()
self.dappsEnabled = getEnv("FLAG_DAPPS_ENABLED", boolToEnv(DEFAULT_FLAG_DAPPS_ENABLED)) != "0"
self.swapEnabled = getEnv("FLAG_SWAP_ENABLED", boolToEnv(DEFAULT_FLAG_SWAP_ENABLED)) != "0"
self.connectorEnabled = getEnv("FLAG_CONNECTOR_ENABLED", boolToEnv(DEFAULT_FLAG_CONNECTOR_ENABLED)) != "0"
self.sendViaPersonalChatEnabled = getEnv("FLAG_SEND_VIA_PERSONAL_CHAT_ENABLED", boolToEnv(DEFAULT_FLAG_SEND_VIA_PERSONAL_CHAT_ENABLED)) != "0"
self.paymentRequestEnabled = getEnv("FLAG_PAYMENT_REQUEST_ENABLED", boolToEnv(DEFAULT_FLAG_PAYMENT_REQUEST_ENABLED)) != "0"

proc delete*(self: FeatureFlags) =
self.QObject.delete()
Expand Down Expand Up @@ -53,3 +56,9 @@ QtObject:

QtProperty[bool] sendViaPersonalChatEnabled:
read = getSendViaPersonalChatEnabled

proc getPaymentRequestEnabled*(self: FeatureFlags): bool {.slot.} =
return self.paymentRequestEnabled

QtProperty[bool] paymentRequestEnabled:
read = getPaymentRequestEnabled
157 changes: 157 additions & 0 deletions storybook/pages/PaymentRequestModalPage.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import SortFilterProxyModel 0.2
import QtTest 1.15

import StatusQ 0.1
import StatusQ.Controls 0.1
import StatusQ.Core 0.1
import StatusQ.Core.Backpressure 0.1
import StatusQ.Core.Utils 0.1

import utils 1.0
import Storybook 1.0
import Models 1.0

import mainui 1.0
import AppLayouts.Wallet.stores 1.0 as WalletStores
import AppLayouts.Wallet.adaptors 1.0
import AppLayouts.Chat.popups 1.0
import AppLayouts.stores 1.0 as AppLayoutStores
import shared.stores 1.0 as SharedStores

SplitView {
id: root

Logs { id: logs }

orientation: Qt.Horizontal

QtObject {
id: d

function launchPopup() {
const modal = paymentRequestModalComponent.createObject(root)
modal.open()
}

readonly property var accounts: WalletAccountsModel {}
readonly property var flatNetworks: NetworksModel.flatNetworks

readonly property string selectedAccountAddress: ctrlAccount.currentValue ?? ""
readonly property int selectedNetworkChainId: ctrlSelectedNetworkChainId.currentValue ?? -1
}

PopupBackground {
id: popupBg

SplitView.fillWidth: true
SplitView.fillHeight: true

Button {
id: reopenButton
anchors.centerIn: parent
text: "Reopen"
enabled: !paymentRequestModalComponent.visible

onClicked: d.launchPopup()
}

Component.onCompleted: Qt.callLater(d.launchPopup)

Component {
id: paymentRequestModalComponent
PaymentRequestModal {
id: paymentRequestModal
modal: false
closePolicy: Popup.CloseOnEscape
destroyOnClose: true

currentCurrency: currenciesStore.currentCurrency
formatCurrencyAmount: currenciesStore.formatCurrencyAmount
flatNetworksModel: d.flatNetworks
accountsModel: d.accounts
assetsModel: tokenAdaptor.outputAssetsModel

readonly property SharedStores.CurrenciesStore currenciesStore: SharedStores.CurrenciesStore {}
readonly property var tokenAdaptor: TokenSelectorViewAdaptor {
assetsModel: null
flatNetworksModel: d.flatNetworks
currentCurrency: paymentRequestModal.currentCurrency
plainTokensBySymbolModel: TokensBySymbolModel {}
showAllTokens: true
}

Connections {
target: d
function onSelectedNetworkChainIdChanged() {
paymentRequestModal.selectedNetworkChainId = d.selectedNetworkChainId
}
function onSelectedAccountAddressChanged() {
paymentRequestModal.selectedAccountAddress = d.selectedAccountAddress
}
}
Component.onCompleted: {
if (d.selectedNetworkChainId > -1)
paymentRequestModal.selectedNetworkChainId = d.selectedNetworkChainId
if (!!d.selectedAccountAddress)
paymentRequestModal.selectedAccountAddress = d.selectedAccountAddress
}
}
}
}

ScrollView {
id: rightPanel
SplitView.minimumWidth: 300
SplitView.preferredWidth: 300
SplitView.minimumHeight: 300

ColumnLayout {
anchors.top: parent.top
anchors.left: parent.left
anchors.margins: 10
spacing: 10

Label {
text: "pre-selection:"
}

RowLayout {
Layout.fillWidth: true
Label {
text: "Chain:"
}
ComboBox {
Layout.fillWidth: true
id: ctrlSelectedNetworkChainId
model: d.flatNetworks
textRole: "chainName"
valueRole: "chainId"
displayText: currentIndex === -1 ? "All chains" : currentText
currentIndex: -1 // all chains
}
}

RowLayout {
Layout.fillWidth: true
Label { text: "Account:" }
ComboBox {
Layout.fillWidth: true
id: ctrlAccount
textRole: "name"
valueRole: "address"
displayText: currentText || "----"
model: SortFilterProxyModel {
sourceModel: d.accounts
sorters: RoleSorter { roleName: "position" }
}
currentIndex: -1
}
}
}
}
}

// category: Popups
19 changes: 19 additions & 0 deletions storybook/pages/StatusChatInputPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import shared.stores 1.0 as SharedStores

import StatusQ.Core.Utils 0.1 as SQUtils

import AppLayouts.Wallet.stores 1.0 as WalletStores
import AppLayouts.Chat.stores 1.0 as ChatStores

SplitView {
Expand Down Expand Up @@ -99,6 +100,9 @@ SplitView {
}
}

paymentRequestFeatureEnabled: true
areTestNetworksEnabled: testnetEnabledCheckBox.checked

onSendMessage: {
logs.logEvent("StatusChatInput::sendMessage", ["MessageWithPk"], [chatInput.getTextWithPublicKeys()])
logs.logEvent("StatusChatInput::sendMessage", ["PlainText"], [SQUtils.StringUtils.plainText(chatInput.getTextWithPublicKeys())])
Expand Down Expand Up @@ -138,6 +142,15 @@ SplitView {

QtObject {
id: d

readonly property var walletAssetsStore: WalletStores.WalletAssetsStore {
id: thisWalletAssetStore
walletTokensStore: WalletStores.TokensStore {
plainTokensBySymbolModel: TokensBySymbolModel {}
}
assetsWithFilteredBalances: thisWalletAssetStore.groupedAccountsAssetsModel
}

property bool linkPreviewsEnabled: linkPreviewSwitch.checked && !askToEnableLinkPreviewSwitch.checked
onLinkPreviewsEnabledChanged: {
loadLinkPreviews(chatInputLoader.item ? chatInputLoader.item.unformattedText : "")
Expand Down Expand Up @@ -172,6 +185,12 @@ SplitView {
checked: true
}

CheckBox {
id: testnetEnabledCheckBox
text: "testnet enabled"
checked: false
}

TabBar {
id: bar
TabButton {
Expand Down
Loading

0 comments on commit 5bf4ba2

Please sign in to comment.