2024-01-04 12:22:12 +00:00
import QtQuick 2.14
import QtQuick . Layouts 1.14
import StatusQ . Controls 0.1
import StatusQ . Core 0.1
import StatusQ . Core . Theme 0.1
import StatusQ . Components 0.1
import utils 1.0
2024-01-29 13:29:15 +00:00
import AppLayouts . Wallet 1.0
2024-01-04 12:22:12 +00:00
ActivityNotificationBase {
id: root
2024-05-22 08:13:39 +00:00
store: null
2024-02-19 13:58:20 +00:00
property var community: null
property var tokenData: root . notification . tokenData
2024-01-29 13:29:15 +00:00
// Community properties:
required property string communityId
2024-01-04 12:22:12 +00:00
required property string communityName
required property string communityImage
2024-01-29 13:29:15 +00:00
// Notification type related properties:
2024-02-19 13:58:20 +00:00
property bool isFirstTokenReceived: root . tokenData . isFirst
readonly property bool isAssetType: root . tokenType === Constants . TokenType . ERC20
2024-01-29 13:29:15 +00:00
// Token related properties:
2024-02-19 13:58:20 +00:00
property string tokenAmount: {
let amount = root . tokenData . amount
// Double check if balance is string, then strip ending zeros (e.g. 1.0 -> 1)
if ( typeof amount === 'string' && amount . endsWith ( '0' ) ) {
amount = parseFloat ( root . tokenData . amount )
if ( isNaN ( amount ) )
amount = "1"
// Cast to Number to drop trailing zeros
amount = Number ( amount ) . toString ( )
}
return amount
}
property string tokenName: root . tokenData . name
property string tokenSymbol: root . tokenData . symbol
property string tokenImage: root . tokenData . imageUrl
property int tokenType: root . tokenData . tokenType
2024-01-29 13:29:15 +00:00
// Wallet related:
2024-02-19 13:58:20 +00:00
property string txHash: root . tokenData . txHash
2024-02-22 14:41:13 +00:00
property string walletAccountName: ! ! root . store && ! root . isFirstTokenReceived ? root . store . walletStore . getNameForWalletAddress ( root . tokenData . walletAddress ) : ""
2024-01-29 13:29:15 +00:00
QtObject {
id: d
readonly property string formattedTokenName: root . isAssetType ? root.tokenSymbol : root . tokenName
readonly property string ctaText: root . isFirstTokenReceived ? qsTr ( "Learn more" ) : qsTr ( "Transaction details" )
readonly property string title: root . isFirstTokenReceived ? ( root . isAssetType ? qsTr ( "You received your first community asset" ) : qsTr ( "You received your first community collectible" ) ) :
qsTr ( "Tokens received" )
2024-02-22 14:41:13 +00:00
readonly property string info: {
if ( root . isFirstTokenReceived ) {
return qsTr ( "%1 %2 was airdropped to you from the %3 community" ) . arg ( root . tokenAmount ) . arg ( d . formattedTokenName ) . arg ( root . communityName )
} else {
return qsTr ( "You were airdropped %1 %2 from %3 to %4" ) . arg ( root . tokenAmount ) . arg ( root . tokenName ) . arg ( root . communityName ) . arg ( root . walletAccountName )
}
}
2024-01-29 13:29:15 +00:00
}
2024-01-04 12:22:12 +00:00
bodyComponent: RowLayout {
spacing: 8
2024-01-29 13:29:15 +00:00
StatusRoundedImage {
Layout.preferredWidth: 44
Layout.preferredHeight: 44
2024-01-04 12:22:12 +00:00
Layout.alignment: Qt . AlignTop
Layout.leftMargin: Style . current . padding
Layout.topMargin: 2
2024-01-29 13:29:15 +00:00
radius: root . isAssetType ? width / 2 : 8
width: 44
height: width
image.source: root . tokenImage
showLoadingIndicator: false
image.fillMode: Image . PreserveAspectCrop
2024-01-04 12:22:12 +00:00
}
ColumnLayout {
spacing: 2
Layout.alignment: Qt . AlignTop
2024-01-29 13:29:15 +00:00
Layout.fillWidth: true
StatusMessageHeader {
Layout.fillWidth: true
displayNameLabel.text: d . title
timestamp: root . notification . timestamp
}
2024-01-04 12:22:12 +00:00
RowLayout {
2024-01-29 13:29:15 +00:00
spacing: Style . current . padding
2024-01-04 12:22:12 +00:00
StatusBaseText {
Layout.fillWidth: true
2024-01-29 13:29:15 +00:00
text: d . info
font.italic: true
2024-01-04 12:22:12 +00:00
wrapMode: Text . WordWrap
2024-01-29 13:29:15 +00:00
color: Theme . palette . baseColor1
2024-01-04 12:22:12 +00:00
}
}
}
}
2024-01-29 13:29:15 +00:00
ctaComponent: StatusFlatButton {
size: StatusBaseButton . Size . Small
text: d . ctaText
onClicked: {
root . closeActivityCenter ( )
if ( root . isFirstTokenReceived ) {
Global . openFirstTokenReceivedPopup ( root . communityId ,
root . communityName ,
root . communityImage ,
root . tokenSymbol ,
root . tokenName ,
root . tokenAmount ,
2024-02-19 13:58:20 +00:00
root . tokenType ,
2024-01-29 13:29:15 +00:00
root . tokenImage ) ;
}
else {
Global . changeAppSectionBySectionType ( Constants . appSection . wallet ,
2024-02-22 14:41:13 +00:00
WalletLayout . LeftPanelSelection . Address ,
WalletLayout . RightPanelSelection . Activity ,
{ address: root . tokenData . walletAddress ,
txHash: root . txHash } )
2024-01-29 13:29:15 +00:00
}
}
}
2024-01-04 12:22:12 +00:00
}