2020-09-29 08:41:27 +00:00
import QtQuick 2.13
import QtQuick . Controls 2.13
import QtQuick . Layouts 1.3
import QtGraphicalEffects 1.0
2022-06-21 08:56:12 +00:00
import QtQml . Models 2.13
2021-09-28 15:04:06 +00:00
2022-07-20 14:54:30 +00:00
import StatusQ . Core 0.1
2021-09-28 15:04:06 +00:00
import utils 1.0
2021-10-27 21:27:49 +00:00
import shared 1.0
import shared . panels 1.0
import shared . popups 1.0
import shared . status 1.0
2022-02-14 23:27:23 +00:00
import shared . stores 1.0 as SharedStores
2021-10-27 21:27:49 +00:00
//TODO remove this dependency!
2022-03-08 18:49:33 +00:00
import AppLayouts . Chat . stores 1.0
2020-09-29 08:41:27 +00:00
Item {
id: root
2022-02-14 23:27:23 +00:00
property var store
2020-09-29 08:41:27 +00:00
property var stickerPacks: StickerPackData { }
2021-12-08 21:20:43 +00:00
property int packId: - 1
2021-07-27 14:04:05 +00:00
2020-09-29 08:41:27 +00:00
signal backClicked
signal uninstallClicked ( int packId )
signal installClicked ( var stickers , int packId , int index )
signal cancelClicked ( int packId )
signal updateClicked ( int packId )
signal buyClicked ( int packId )
2022-07-20 14:54:30 +00:00
StatusGridView {
2020-09-29 08:41:27 +00:00
id: availableStickerPacks
2022-08-11 19:16:59 +00:00
objectName: "stickerMarketStatusGridView"
2020-09-29 08:41:27 +00:00
width: parent . width
height: 380
anchors.left: parent . left
anchors.leftMargin: Style . current . padding
anchors.right: parent . right
anchors.rightMargin: Style . current . padding
anchors.top: parent . top
anchors.topMargin: Style . current . padding
cellWidth: parent . width - ( Style . current . padding * 2 )
cellHeight: height - 72
2022-06-21 08:56:12 +00:00
2020-09-29 08:41:27 +00:00
focus: true
2022-06-21 08:56:12 +00:00
model: DelegateModel {
id: delegateModel
function update ( ) {
if ( items . count > 0 ) {
items . setGroups ( 0 , items . count , "items" ) ;
2020-09-29 08:41:27 +00:00
}
2021-03-26 21:21:50 +00:00
2022-06-21 08:56:12 +00:00
var visible = [ ] ;
for ( var i = 0 ; i < items . count ; ++ i ) {
var item = items . get ( i ) ;
if ( delegateModel . walletEnabled ||
! delegateModel . walletEnabled && item . model . price == 0 ) {
visible . push ( item ) ;
}
2020-09-29 08:41:27 +00:00
}
2021-03-26 21:21:50 +00:00
2022-06-21 08:56:12 +00:00
for ( i = 0 ; i < visible . length ; ++ i ) {
item = visible [ i ] ;
item . inVisible = true ;
if ( item . visibleIndex !== i ) {
visibleItems . move ( item . visibleIndex , i , 1 ) ;
}
2021-03-26 21:21:50 +00:00
}
2022-06-21 08:56:12 +00:00
}
2023-03-15 13:35:03 +00:00
readonly property bool walletEnabled: SharedStores . RootStore . isWalletEnabled
2022-06-21 08:56:12 +00:00
onWalletEnabledChanged: {
update ( )
}
model: stickerPacks
items.onChanged: update ( )
filterOnGroup: "visible"
groups: DelegateModelGroup {
id: visibleItems
2021-03-26 21:21:50 +00:00
2022-06-21 08:56:12 +00:00
name: "visible"
includeByDefault: false
}
delegate: Item {
2022-08-11 19:16:59 +00:00
objectName: "stickerMarketDelegateItem" + index
readonly property string packId: model . packId // This property is necessary for the tests
readonly property bool installed: model . installed // This property is necessary for the tests
2022-06-21 08:56:12 +00:00
width: availableStickerPacks . cellWidth
height: availableStickerPacks . cellHeight
RoundedImage {
id: imgPreview
anchors.top: parent . top
anchors.left: parent . left
2020-09-29 08:41:27 +00:00
anchors.right: parent . right
2022-06-21 08:56:12 +00:00
height: 220
width: parent . width
radius: 12
source: model . preview
onClicked: {
stickerPackDetailsPopup . open ( )
2020-09-29 08:41:27 +00:00
}
}
2022-06-21 08:56:12 +00:00
// TODO: replace with StatusModal
ModalPopup {
id: stickerPackDetailsPopup
height: 540
header: StatusStickerPackDetails {
packThumb: thumbnail
packName: name
packAuthor: author
packNameFontSize: 17
spacing: Style . current . padding / 2
2021-07-27 14:04:05 +00:00
}
2022-06-21 08:56:12 +00:00
contentWrapper.anchors.topMargin: 0
contentWrapper.anchors.bottomMargin: 0
StatusStickerList {
id: stickerGridInPopup
anchors.fill: parent
anchors.topMargin: Style . current . padding
model: stickers
packId: root . packId
2021-07-27 14:04:05 +00:00
}
2022-06-21 08:56:12 +00:00
footer: StatusStickerButton {
2022-08-11 19:16:59 +00:00
objectName: "statusStickerMarketInstallButton"
2022-06-21 08:56:12 +00:00
height: 44
anchors.right: parent . right
style: StatusStickerButton . StyleType . LargeNoIcon
packPrice: price
isInstalled: installed
isBought: bought
isPending: pending
2023-04-04 11:31:04 +00:00
greyedOut: ! root . store . networkConnectionStore . stickersNetworkAvailable
tooltip.text: root . store . networkConnectionStore . stickersNetworkUnavailableText
2022-06-21 08:56:12 +00:00
onInstallClicked: root . installClicked ( stickers , packId , index )
onUninstallClicked: root . uninstallClicked ( packId )
onCancelClicked: root . cancelClicked ( packId )
onUpdateClicked: root . updateClicked ( packId )
onBuyClicked: {
Global . openPopup ( stickerPackPurchaseModal )
root . buyClicked ( packId )
}
}
}
Component {
id: stickerPackPurchaseModal
2022-10-17 10:17:25 +00:00
SendModal {
id: buyStickersModal
interactive: false
sendType: Constants . SendType . StickersBuy
preSelectedRecipient: root . store . stickersStore . getStickersMarketAddress ( )
preDefinedAmountToSend: LocaleUtils . numberToLocaleString ( parseFloat ( price ) )
2023-04-07 10:34:01 +00:00
preSelectedAsset: store . getAsset ( buyStickersModal . store . currentAccount . assets , JSON . parse ( root . store . stickersStore . getStatusToken ( ) ) . symbol )
2022-10-17 10:17:25 +00:00
sendTransaction: function ( ) {
if ( bestRoutes . length === 1 ) {
let path = bestRoutes [ 0 ]
let eip1559Enabled = path . gasFees . eip1559Enabled
2022-11-30 12:59:21 +00:00
let maxFeePerGas = path . gasFees . maxFeePerGasM
2022-10-17 10:17:25 +00:00
root . store . stickersStore . authenticateAndBuy ( packId ,
selectedAccount . address ,
path . gasAmount ,
eip1559Enabled ? "" : path . gasFees . gasPrice ,
eip1559Enabled ? path.gasFees.maxPriorityFeePerGas : "" ,
eip1559Enabled ? maxFeePerGas : path . gasFees . gasPrice ,
eip1559Enabled )
}
2022-06-21 08:56:12 +00:00
}
2022-10-17 10:17:25 +00:00
Connections {
target: root . store . stickersStore . stickersModule
2023-01-18 09:25:36 +00:00
function onTransactionWasSent ( txResult: string ) {
2022-10-17 10:17:25 +00:00
try {
let response = JSON . parse ( txResult )
if ( ! response . success ) {
2022-11-30 18:57:00 +00:00
if ( response . result . includes ( Constants . walletSection . cancelledMessage ) ) {
2022-10-17 10:17:25 +00:00
return
}
buyStickersModal . sendingError . text = response . result
return buyStickersModal . sendingError . open ( )
}
2022-12-08 15:56:02 +00:00
for ( var i = 0 ; i < buyStickersModal . bestRoutes . length ; i ++ ) {
let url = "%1/%2" . arg ( buyStickersModal . store . getEtherscanLink ( buyStickersModal . bestRoutes [ i ] . fromNetwork . chainId ) ) . arg ( response . result )
Global . displayToastMessage ( qsTr ( "Transaction pending..." ) ,
qsTr ( "View on etherscan" ) ,
"" ,
true ,
Constants . ephemeralNotificationType . normal ,
url )
}
2022-10-17 10:17:25 +00:00
buyStickersModal . close ( )
} catch ( e ) {
console . error ( 'Error parsing the response' , e )
}
}
2022-06-21 08:56:12 +00:00
}
2020-11-03 10:29:56 +00:00
}
2021-07-27 14:04:05 +00:00
}
2022-06-21 08:56:12 +00:00
StatusStickerPackDetails {
id: stickerPackDetails
height: 64 - ( Style . current . smallPadding * 2 )
width: parent . width - ( Style . current . padding * 2 )
anchors.top: imgPreview . bottom
anchors.topMargin: Style . current . smallPadding
anchors.bottomMargin: Style . current . smallPadding
anchors.left: parent . left
2020-09-29 08:41:27 +00:00
anchors.right: parent . right
2022-06-21 08:56:12 +00:00
packThumb: thumbnail
packName: name
packAuthor: author
StatusStickerButton {
anchors.right: parent . right
packPrice: price
width: 75 // only needed for Qt Creator
isInstalled: installed
isBought: bought
isPending: pending
2023-04-04 11:31:04 +00:00
greyedOut: ! root . store . networkConnectionStore . stickersNetworkAvailable
tooltip.text: root . store . networkConnectionStore . stickersNetworkUnavailableText
2022-06-21 08:56:12 +00:00
onInstallClicked: root . installClicked ( stickers , packId , index )
onUninstallClicked: root . uninstallClicked ( packId )
onCancelClicked: root . cancelClicked ( packId )
onUpdateClicked: root . updateClicked ( packId )
onBuyClicked: {
if ( ! SharedStores . RootStore . isWalletEnabled ) {
confirmationPopup . open ( )
return
}
Global . openPopup ( stickerPackPurchaseModal )
root . buyClicked ( packId )
2021-08-25 08:09:33 +00:00
}
2020-09-29 08:41:27 +00:00
}
}
2021-08-25 08:09:33 +00:00
2022-06-21 08:56:12 +00:00
ConfirmationDialog {
id: confirmationPopup
showCancelButton: true
confirmationText: qsTr ( "This feature is experimental and is meant for testing purposes by core contributors and the community. It's not meant for real use and makes no claims of security or integrity of funds or data. Use at your own risk." )
confirmButtonLabel: qsTr ( "I understand" )
onConfirmButtonClicked: {
SharedStores . RootStore . enableWallet ( ) ;
close ( )
Global . openPopup ( stickerPackPurchaseModal )
root . buyClicked ( packId )
}
2021-08-25 08:09:33 +00:00
2022-06-21 08:56:12 +00:00
onCancelButtonClicked: {
close ( )
}
2021-08-25 08:09:33 +00:00
}
}
2020-09-29 08:41:27 +00:00
}
}
Item {
id: footer
height: 44 - Style . current . padding
anchors.top: availableStickerPacks . bottom
RoundedIcon {
id: btnBack
anchors.top: parent . top
anchors.topMargin: Style . current . padding / 2
anchors.left: parent . left
anchors.leftMargin: Style . current . padding / 2
width: 28
height: 28
iconWidth: 17.5
iconHeight: 13.5
2021-03-26 21:21:50 +00:00
iconColor: Style . current . roundedButtonSecondaryForegroundColor
2021-09-28 15:04:06 +00:00
source: Style . svg ( "arrowUp" )
2020-09-29 08:41:27 +00:00
rotation: 270
onClicked: {
root . backClicked ( )
}
}
}
}
/ * # # ^ # #
Designer {
D { i: 0 ; height: 440 ; width: 360 }
}
# # ^ # # * /