2023-09-01 09:27:44 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
|
|
|
|
import shared.stores 1.0
|
|
|
|
|
|
|
|
import StatusQ.Core.Utils 0.1
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
enum FeeType {
|
|
|
|
Airdrop,
|
|
|
|
Deploy,
|
|
|
|
SelfDestruct,
|
2023-10-23 11:32:50 +00:00
|
|
|
Burn,
|
|
|
|
SetSigner
|
2023-09-01 09:27:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
property CommunityTokensStore communityTokensStore
|
2024-10-04 11:01:08 +00:00
|
|
|
property alias active: feesBroker.active
|
2023-09-01 09:27:44 +00:00
|
|
|
|
|
|
|
property QtObject d: QtObject {
|
|
|
|
id: internal
|
|
|
|
|
|
|
|
component AirdropFeeSubscription: Subscription {
|
|
|
|
required property AirdropFeesSubscriber subscriber
|
|
|
|
readonly property var requestArgs: ({
|
|
|
|
type: TransactionFeesBroker.FeeType.Airdrop,
|
|
|
|
communityId: subscriber.communityId,
|
|
|
|
contractKeysAndAmounts: subscriber.contractKeysAndAmounts,
|
|
|
|
addressesToAirdrop: subscriber.addressesToAirdrop,
|
|
|
|
feeAccountAddress: subscriber.feeAccountAddress
|
|
|
|
})
|
|
|
|
|
|
|
|
isReady: !!subscriber.communityId &&
|
|
|
|
!!subscriber.contractKeysAndAmounts &&
|
|
|
|
!!subscriber.addressesToAirdrop &&
|
|
|
|
!!subscriber.feeAccountAddress &&
|
|
|
|
subscriber.contractKeysAndAmounts.length &&
|
|
|
|
subscriber.addressesToAirdrop.length &&
|
|
|
|
subscriber.enabled
|
|
|
|
|
|
|
|
topic: isReady ? JSON.stringify(requestArgs) : ""
|
|
|
|
onResponseChanged: subscriber.airdropFeesResponse = response
|
|
|
|
}
|
|
|
|
|
|
|
|
component DeployFeeSubscription: Subscription {
|
|
|
|
required property DeployFeesSubscriber subscriber
|
|
|
|
readonly property var requestArgs: ({
|
|
|
|
type: TransactionFeesBroker.FeeType.Deploy,
|
2023-08-30 07:20:28 +00:00
|
|
|
communityId: subscriber.communityId,
|
2023-09-01 09:27:44 +00:00
|
|
|
chainId: subscriber.chainId,
|
|
|
|
accountAddress: subscriber.accountAddress,
|
|
|
|
tokenType: subscriber.tokenType,
|
|
|
|
isOwnerDeployment: subscriber.isOwnerDeployment
|
|
|
|
})
|
|
|
|
|
|
|
|
isReady: !!subscriber.chainId &&
|
|
|
|
!!subscriber.accountAddress &&
|
|
|
|
!!subscriber.tokenType &&
|
|
|
|
subscriber.enabled
|
|
|
|
|
|
|
|
topic: isReady ? JSON.stringify(requestArgs) : ""
|
|
|
|
onResponseChanged: subscriber.feesResponse = response
|
|
|
|
}
|
|
|
|
|
|
|
|
component SelfDestructFeeSubscription: Subscription {
|
|
|
|
required property SelfDestructFeesSubscriber subscriber
|
|
|
|
readonly property var requestArgs: ({
|
|
|
|
type: TransactionFeesBroker.FeeType.SelfDestruct,
|
|
|
|
walletsAndAmounts:subscriber.walletsAndAmounts,
|
|
|
|
tokenKey: subscriber.tokenKey,
|
|
|
|
accountAddress: subscriber.accountAddress,
|
|
|
|
})
|
|
|
|
isReady: !!subscriber.walletsAndAmounts &&
|
|
|
|
!!subscriber.tokenKey &&
|
|
|
|
!!subscriber.accountAddress &&
|
|
|
|
subscriber.walletsAndAmounts.length &&
|
|
|
|
subscriber.enabled
|
|
|
|
|
|
|
|
topic: isReady ? JSON.stringify(requestArgs) : ""
|
|
|
|
onResponseChanged: subscriber.feesResponse = response
|
|
|
|
}
|
|
|
|
|
|
|
|
component BurnTokenFeeSubscription: Subscription {
|
|
|
|
required property BurnTokenFeesSubscriber subscriber
|
|
|
|
readonly property var requestArgs: ({
|
|
|
|
type: TransactionFeesBroker.FeeType.Burn,
|
|
|
|
tokenKey: subscriber.tokenKey,
|
|
|
|
amount: subscriber.amount,
|
|
|
|
accountAddress: subscriber.accountAddress
|
|
|
|
})
|
|
|
|
isReady: !!subscriber.tokenKey &&
|
|
|
|
!!subscriber.amount &&
|
|
|
|
!!subscriber.accountAddress &&
|
|
|
|
subscriber.enabled
|
|
|
|
|
|
|
|
topic: isReady ? JSON.stringify(requestArgs) : ""
|
|
|
|
onResponseChanged: subscriber.feesResponse = response
|
|
|
|
}
|
|
|
|
|
2023-10-23 11:32:50 +00:00
|
|
|
component SetSignerFeeSubscription: Subscription {
|
|
|
|
required property SetSignerFeesSubscriber subscriber
|
|
|
|
readonly property var requestArgs: ({
|
|
|
|
type: TransactionFeesBroker.FeeType.SetSigner,
|
2023-10-23 11:36:33 +00:00
|
|
|
chainId: subscriber.chainId,
|
|
|
|
contractAddress: subscriber.contractAddress,
|
2023-10-23 11:32:50 +00:00
|
|
|
accountAddress: subscriber.accountAddress
|
|
|
|
})
|
2023-10-23 11:36:33 +00:00
|
|
|
isReady: !!subscriber.chainId &&
|
|
|
|
!!subscriber.contractAddress &&
|
2023-10-23 11:32:50 +00:00
|
|
|
!!subscriber.accountAddress &&
|
|
|
|
subscriber.enabled
|
|
|
|
|
|
|
|
topic: isReady ? JSON.stringify(requestArgs) : ""
|
|
|
|
onResponseChanged: subscriber.feesResponse = response
|
|
|
|
}
|
|
|
|
|
2023-09-01 09:27:44 +00:00
|
|
|
readonly property Component airdropFeeSubscriptionComponent: AirdropFeeSubscription {}
|
|
|
|
readonly property Component deployFeeSubscriptionComponent: DeployFeeSubscription {}
|
|
|
|
readonly property Component selfDestructFeeSubscriptionComponent: SelfDestructFeeSubscription {}
|
|
|
|
readonly property Component burnFeeSubscriptionComponent: BurnTokenFeeSubscription {}
|
2023-10-23 11:32:50 +00:00
|
|
|
readonly property Component setSignerFeeSubscriptionComponent: SetSignerFeeSubscription {}
|
2023-09-01 09:27:44 +00:00
|
|
|
|
|
|
|
readonly property SubscriptionBroker feesBroker: SubscriptionBroker {
|
2024-10-04 11:01:08 +00:00
|
|
|
id: feesBroker
|
|
|
|
|
2023-09-01 09:27:44 +00:00
|
|
|
onRequest: internal.computeFee(topic)
|
|
|
|
}
|
|
|
|
|
|
|
|
property Connections communityTokensStoreConnections: Connections {
|
|
|
|
target: communityTokensStore
|
|
|
|
|
|
|
|
function onDeployFeeUpdated(ethCurrency, fiatCurrency, errorCode, responseId) {
|
|
|
|
d.feesBroker.response(responseId, { ethCurrency: ethCurrency, fiatCurrency: fiatCurrency, errorCode: errorCode })
|
|
|
|
}
|
2023-09-28 10:09:47 +00:00
|
|
|
|
2023-09-01 09:27:44 +00:00
|
|
|
function onAirdropFeeUpdated(response) {
|
|
|
|
d.feesBroker.response(response.requestId, response)
|
|
|
|
}
|
|
|
|
|
|
|
|
function onSelfDestructFeeUpdated(ethCurrency, fiatCurrency, errorCode, responseId) {
|
|
|
|
d.feesBroker.response(responseId, { ethCurrency: ethCurrency, fiatCurrency: fiatCurrency, errorCode: errorCode })
|
|
|
|
}
|
|
|
|
|
|
|
|
function onBurnFeeUpdated(ethCurrency, fiatCurrency, errorCode, responseId) {
|
|
|
|
d.feesBroker.response(responseId, { ethCurrency: ethCurrency, fiatCurrency: fiatCurrency, errorCode: errorCode })
|
|
|
|
}
|
2023-10-23 11:36:33 +00:00
|
|
|
|
|
|
|
function onSetSignerFeeUpdated(ethCurrency, fiatCurrency, errorCode, responseId) {
|
|
|
|
d.feesBroker.response(responseId, { ethCurrency: ethCurrency, fiatCurrency: fiatCurrency, errorCode: errorCode })
|
|
|
|
}
|
2023-09-01 09:27:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function computeFee(topic) {
|
|
|
|
const args = JSON.parse(topic)
|
|
|
|
switch (args.type) {
|
|
|
|
case TransactionFeesBroker.FeeType.Airdrop:
|
|
|
|
computeAirdropFee(args, topic)
|
|
|
|
break
|
|
|
|
case TransactionFeesBroker.FeeType.Deploy:
|
|
|
|
computeDeployFee(args, topic)
|
|
|
|
break
|
|
|
|
case TransactionFeesBroker.FeeType.SelfDestruct:
|
|
|
|
computeSelfDestructFee(args, topic)
|
|
|
|
break
|
|
|
|
case TransactionFeesBroker.FeeType.Burn:
|
|
|
|
computeBurnFee(args, topic)
|
|
|
|
break
|
2023-10-23 11:32:50 +00:00
|
|
|
case TransactionFeesBroker.FeeType.SetSigner:
|
|
|
|
computeSetSignerFee(args, topic)
|
|
|
|
break
|
2023-09-01 09:27:44 +00:00
|
|
|
default:
|
|
|
|
console.error("Unknown fee type: " + args.type)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function computeAirdropFee(args, topic) {
|
|
|
|
communityTokensStore.computeAirdropFee(
|
|
|
|
args.communityId,
|
|
|
|
args.contractKeysAndAmounts,
|
|
|
|
args.addressesToAirdrop,
|
|
|
|
args.feeAccountAddress,
|
|
|
|
topic)
|
|
|
|
}
|
|
|
|
|
|
|
|
function computeDeployFee(args, topic) {
|
2023-08-30 07:20:28 +00:00
|
|
|
communityTokensStore.computeDeployFee(args.communityId, args.chainId, args.accountAddress, args.tokenType, args.isOwnerDeployment, topic)
|
2023-09-01 09:27:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function computeSelfDestructFee(args, topic) {
|
|
|
|
communityTokensStore.computeSelfDestructFee(args.walletsAndAmounts, args.tokenKey, args.accountAddress, topic)
|
|
|
|
}
|
|
|
|
|
|
|
|
function computeBurnFee(args, topic) {
|
|
|
|
console.assert(typeof args.amount === "string")
|
|
|
|
communityTokensStore.computeBurnFee(args.tokenKey, args.amount, args.accountAddress, topic)
|
|
|
|
}
|
2023-10-23 11:32:50 +00:00
|
|
|
|
|
|
|
function computeSetSignerFee(args, topic) {
|
2023-10-23 11:36:33 +00:00
|
|
|
communityTokensStore.computeSetSignerFee(args.chainId, args.contractAddress, args.accountAddress, topic)
|
2023-10-23 11:32:50 +00:00
|
|
|
}
|
2023-09-01 09:27:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function registerAirdropFeesSubscriber(subscriberObj) {
|
|
|
|
const subscription = d.airdropFeeSubscriptionComponent.createObject(subscriberObj, { subscriber: subscriberObj })
|
|
|
|
d.feesBroker.subscribe(subscription)
|
|
|
|
}
|
|
|
|
|
|
|
|
function registerDeployFeesSubscriber(subscriberObj) {
|
|
|
|
const subscription = d.deployFeeSubscriptionComponent.createObject(subscriberObj, { subscriber: subscriberObj })
|
|
|
|
d.feesBroker.subscribe(subscription)
|
|
|
|
}
|
|
|
|
|
|
|
|
function registerSelfDestructFeesSubscriber(subscriberObj) {
|
|
|
|
const subscription = d.selfDestructFeeSubscriptionComponent.createObject(subscriberObj, { subscriber: subscriberObj })
|
|
|
|
d.feesBroker.subscribe(subscription)
|
|
|
|
}
|
|
|
|
|
|
|
|
function registerBurnFeesSubscriber(subscriberObj) {
|
|
|
|
const subscription = d.burnFeeSubscriptionComponent.createObject(subscriberObj, { subscriber: subscriberObj })
|
|
|
|
d.feesBroker.subscribe(subscription)
|
|
|
|
}
|
2023-10-23 11:32:50 +00:00
|
|
|
|
|
|
|
function registerSetSignerFeesSubscriber(subscriberObj) {
|
|
|
|
const subscription = d.setSignerFeeSubscriptionComponent.createObject(subscriberObj, { subscriber: subscriberObj })
|
|
|
|
d.feesBroker.subscribe(subscription)
|
|
|
|
}
|
2023-09-01 09:27:44 +00:00
|
|
|
}
|