fix(@desktop/communities): Computing fees in ETH and USD for Sign Transaction dialog
Issue #10007
This commit is contained in:
parent
2142a6bf9c
commit
d759bda81d
|
@ -216,7 +216,7 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController =
|
||||||
result.settingsService, result.walletAccountService, result.transactionService,
|
result.settingsService, result.walletAccountService, result.transactionService,
|
||||||
result.networkService, result.tokenService)
|
result.networkService, result.tokenService)
|
||||||
result.tokensService = tokens_service.newService(statusFoundation.events, statusFoundation.threadpool,
|
result.tokensService = tokens_service.newService(statusFoundation.events, statusFoundation.threadpool,
|
||||||
result.transactionService)
|
result.transactionService, result.tokenService, result.settingsService)
|
||||||
result.providerService = provider_service.newService(statusFoundation.events, statusFoundation.threadpool, result.ensService)
|
result.providerService = provider_service.newService(statusFoundation.events, statusFoundation.threadpool, result.ensService)
|
||||||
result.networkConnectionService = network_connection_service.newService(statusFoundation.events, result.walletAccountService, result.networkService, result.collectibleService, result.nodeService)
|
result.networkConnectionService = network_connection_service.newService(statusFoundation.events, result.walletAccountService, result.networkService, result.collectibleService, result.nodeService)
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ import ../../../../app_service/common/types
|
||||||
import ../../../../app_service/service/community/service as community_service
|
import ../../../../app_service/service/community/service as community_service
|
||||||
import ../../../../app_service/service/contacts/service as contacts_service
|
import ../../../../app_service/service/contacts/service as contacts_service
|
||||||
import ../../../../app_service/service/network/service as networks_service
|
import ../../../../app_service/service/network/service as networks_service
|
||||||
|
import ../../../../app_service/service/transaction/service as transaction_service
|
||||||
import ../../../../app_service/service/community_tokens/service as community_tokens_service
|
import ../../../../app_service/service/community_tokens/service as community_tokens_service
|
||||||
import ../../../../app_service/service/chat/dto/chat
|
import ../../../../app_service/service/chat/dto/chat
|
||||||
import ./tokens/models/token_item
|
import ./tokens/models/token_item
|
||||||
|
@ -56,7 +57,8 @@ proc newModule*(
|
||||||
communityService: community_service.Service,
|
communityService: community_service.Service,
|
||||||
contactsService: contacts_service.Service,
|
contactsService: contacts_service.Service,
|
||||||
communityTokensService: community_tokens_service.Service,
|
communityTokensService: community_tokens_service.Service,
|
||||||
networksService: networks_service.Service): Module =
|
networksService: networks_service.Service,
|
||||||
|
transactionService: transaction_service.Service): Module =
|
||||||
result = Module()
|
result = Module()
|
||||||
result.delegate = delegate
|
result.delegate = delegate
|
||||||
result.view = newView(result)
|
result.view = newView(result)
|
||||||
|
@ -69,7 +71,7 @@ proc newModule*(
|
||||||
communityTokensService,
|
communityTokensService,
|
||||||
networksService,
|
networksService,
|
||||||
)
|
)
|
||||||
result.communityTokensModule = community_tokens_module.newCommunityTokensModule(result, events, communityTokensService)
|
result.communityTokensModule = community_tokens_module.newCommunityTokensModule(result, events, communityTokensService, transactionService)
|
||||||
result.moduleLoaded = false
|
result.moduleLoaded = false
|
||||||
result.curatedCommunitiesLoaded = false
|
result.curatedCommunitiesLoaded = false
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import ./io_interface as community_tokens_module_interface
|
import ./io_interface as community_tokens_module_interface
|
||||||
|
|
||||||
import ../../../../../app_service/service/community_tokens/service as community_tokens_service
|
import ../../../../../app_service/service/community_tokens/service as community_tokens_service
|
||||||
|
import ../../../../../app_service/service/transaction/service as transaction_service
|
||||||
import ../../../../../app_service/service/community/dto/community
|
import ../../../../../app_service/service/community/dto/community
|
||||||
import ../../../../core/signals/types
|
import ../../../../core/signals/types
|
||||||
import ../../../../core/eventemitter
|
import ../../../../core/eventemitter
|
||||||
|
@ -14,16 +15,19 @@ type
|
||||||
communityTokensModule: community_tokens_module_interface.AccessInterface
|
communityTokensModule: community_tokens_module_interface.AccessInterface
|
||||||
events: EventEmitter
|
events: EventEmitter
|
||||||
communityTokensService: community_tokens_service.Service
|
communityTokensService: community_tokens_service.Service
|
||||||
|
transactionService: transaction_service.Service
|
||||||
|
|
||||||
proc newCommunityTokensController*(
|
proc newCommunityTokensController*(
|
||||||
communityTokensModule: community_tokens_module_interface.AccessInterface,
|
communityTokensModule: community_tokens_module_interface.AccessInterface,
|
||||||
events: EventEmitter,
|
events: EventEmitter,
|
||||||
communityTokensService: community_tokens_service.Service
|
communityTokensService: community_tokens_service.Service,
|
||||||
|
transactionService: transaction_service.Service
|
||||||
): Controller =
|
): Controller =
|
||||||
result = Controller()
|
result = Controller()
|
||||||
result.communityTokensModule = communityTokensModule
|
result.communityTokensModule = communityTokensModule
|
||||||
result.events = events
|
result.events = events
|
||||||
result.communityTokensService = communityTokensService
|
result.communityTokensService = communityTokensService
|
||||||
|
result.transactionService = transactionService
|
||||||
|
|
||||||
proc delete*(self: Controller) =
|
proc delete*(self: Controller) =
|
||||||
discard
|
discard
|
||||||
|
@ -44,3 +48,9 @@ proc authenticateUser*(self: Controller, keyUid = "") =
|
||||||
|
|
||||||
proc getCommunityTokens*(self: Controller, communityId: string): seq[CommunityTokenDto] =
|
proc getCommunityTokens*(self: Controller, communityId: string): seq[CommunityTokenDto] =
|
||||||
return self.communityTokensService.getCommunityTokens(communityId)
|
return self.communityTokensService.getCommunityTokens(communityId)
|
||||||
|
|
||||||
|
proc getSuggestedFees*(self: Controller, chainId: int): SuggestedFeesDto =
|
||||||
|
return self.transactionService.suggestedFees(chainId)
|
||||||
|
|
||||||
|
proc getFiatValue*(self: Controller, cryptoBalance: string, cryptoSymbol: string): string =
|
||||||
|
return self.communityTokensService.getFiatValue(cryptoBalance, cryptoSymbol)
|
||||||
|
|
|
@ -18,3 +18,6 @@ method onUserAuthenticated*(self: AccessInterface, password: string) {.base.} =
|
||||||
|
|
||||||
method resetTempValues*(self: AccessInterface) {.base.} =
|
method resetTempValues*(self: AccessInterface) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
method computeDeployFee*(self: AccessInterface, chainId: int): string {.base.} =
|
||||||
|
raise newException(ValueError, "No implementation available")
|
|
@ -1,7 +1,9 @@
|
||||||
import NimQml, json
|
import NimQml, json, stint, strformat, strutils
|
||||||
|
|
||||||
import ../../../../../app_service/service/community_tokens/service as community_tokens_service
|
import ../../../../../app_service/service/community_tokens/service as community_tokens_service
|
||||||
|
import ../../../../../app_service/service/transaction/service as transaction_service
|
||||||
import ../../../../../app_service/service/community/dto/community
|
import ../../../../../app_service/service/community/dto/community
|
||||||
|
import ../../../../../app_service/common/conversion
|
||||||
import ../../../../core/eventemitter
|
import ../../../../core/eventemitter
|
||||||
import ../../../../global/global_singleton
|
import ../../../../global/global_singleton
|
||||||
import ../io_interface as parent_interface
|
import ../io_interface as parent_interface
|
||||||
|
@ -24,12 +26,13 @@ type
|
||||||
proc newCommunityTokensModule*(
|
proc newCommunityTokensModule*(
|
||||||
parent: parent_interface.AccessInterface,
|
parent: parent_interface.AccessInterface,
|
||||||
events: EventEmitter,
|
events: EventEmitter,
|
||||||
communityTokensService: community_tokens_service.Service): Module =
|
communityTokensService: community_tokens_service.Service,
|
||||||
|
transactionService: transaction_service.Service): Module =
|
||||||
result = Module()
|
result = Module()
|
||||||
result.parent = parent
|
result.parent = parent
|
||||||
result.view = newView(result)
|
result.view = newView(result)
|
||||||
result.viewVariant = newQVariant(result.view)
|
result.viewVariant = newQVariant(result.view)
|
||||||
result.controller = controller.newCommunityTokensController(result, events, communityTokensService)
|
result.controller = controller.newCommunityTokensController(result, events, communityTokensService, transactionService)
|
||||||
|
|
||||||
method delete*(self: Module) =
|
method delete*(self: Module) =
|
||||||
self.view.delete
|
self.view.delete
|
||||||
|
@ -74,3 +77,20 @@ method onUserAuthenticated*(self: Module, password: string) =
|
||||||
#TODO signalize somehow
|
#TODO signalize somehow
|
||||||
else:
|
else:
|
||||||
self.controller.deployCollectibles(self.tempCommunityId, self.tempAddressFrom, password, self.tempDeploymentParams, self.tempTokenMetadata, self.tempChainId)
|
self.controller.deployCollectibles(self.tempCommunityId, self.tempAddressFrom, password, self.tempDeploymentParams, self.tempTokenMetadata, self.tempChainId)
|
||||||
|
|
||||||
|
method computeDeployFee*(self: Module, chainId: int): string =
|
||||||
|
let suggestedFees = self.controller.getSuggestedFees(chainId)
|
||||||
|
if suggestedFees == nil:
|
||||||
|
return "-"
|
||||||
|
|
||||||
|
let contractGasUnits = 3702411 # this should go from status-go
|
||||||
|
let maxFees = suggestedFees.maxFeePerGasM
|
||||||
|
let gasPrice = if suggestedFees.eip1559Enabled: maxFees else: suggestedFees.gasPrice
|
||||||
|
|
||||||
|
let weiValue = gwei2Wei(gasPrice) * contractGasUnits.u256
|
||||||
|
let ethValueStr = wei2Eth(weiValue)
|
||||||
|
let ethValue = parseFloat(ethValueStr)
|
||||||
|
|
||||||
|
let fiatValue = self.controller.getFiatValue(ethValueStr, "ETH")
|
||||||
|
|
||||||
|
return fmt"{ethValue:.4f}ETH (${fiatValue})"
|
|
@ -6,6 +6,7 @@ QtObject:
|
||||||
type
|
type
|
||||||
View* = ref object of QObject
|
View* = ref object of QObject
|
||||||
communityTokensModule: community_tokens_module_interface.AccessInterface
|
communityTokensModule: community_tokens_module_interface.AccessInterface
|
||||||
|
deployFee: string
|
||||||
|
|
||||||
proc load*(self: View) =
|
proc load*(self: View) =
|
||||||
discard
|
discard
|
||||||
|
@ -21,7 +22,16 @@ QtObject:
|
||||||
proc deployCollectible*(self: View, communityId: string, fromAddress: string, name: string, symbol: string, description: string, supply: int, infiniteSupply: bool, transferable: bool, selfDestruct: bool, chainId: int, image: string) {.slot.} =
|
proc deployCollectible*(self: View, communityId: string, fromAddress: string, name: string, symbol: string, description: string, supply: int, infiniteSupply: bool, transferable: bool, selfDestruct: bool, chainId: int, image: string) {.slot.} =
|
||||||
self.communityTokensModule.deployCollectible(communityId, fromAddress, name, symbol, description, supply, infiniteSupply, transferable, selfDestruct, chainId, image)
|
self.communityTokensModule.deployCollectible(communityId, fromAddress, name, symbol, description, supply, infiniteSupply, transferable, selfDestruct, chainId, image)
|
||||||
|
|
||||||
|
proc deployFeeUpdated*(self: View) {.signal.}
|
||||||
|
|
||||||
|
proc computeDeployFee*(self: View, chainId: int) {.slot.} =
|
||||||
|
self.deployFee = self.communityTokensModule.computeDeployFee(chainId)
|
||||||
|
self.deployFeeUpdated()
|
||||||
|
|
||||||
|
proc getDeployFee(self: View): QVariant {.slot.} =
|
||||||
|
return newQVariant(self.deployFee)
|
||||||
|
|
||||||
|
QtProperty[QVariant] deployFee:
|
||||||
|
read = getDeployFee
|
||||||
|
notify = deployFeeUpdated
|
||||||
|
|
||||||
|
|
|
@ -207,7 +207,7 @@ proc newModule*[T](
|
||||||
result.stickersModule = stickers_module.newModule(result, events, stickersService, settingsService, walletAccountService, networkService, tokenService)
|
result.stickersModule = stickers_module.newModule(result, events, stickersService, settingsService, walletAccountService, networkService, tokenService)
|
||||||
result.activityCenterModule = activity_center_module.newModule(result, events, activityCenterService, contactsService,
|
result.activityCenterModule = activity_center_module.newModule(result, events, activityCenterService, contactsService,
|
||||||
messageService, chatService, communityService)
|
messageService, chatService, communityService)
|
||||||
result.communitiesModule = communities_module.newModule(result, events, communityService, contactsService, communityTokensService, networkService)
|
result.communitiesModule = communities_module.newModule(result, events, communityService, contactsService, communityTokensService, networkService, transactionService)
|
||||||
result.appSearchModule = app_search_module.newModule(result, events, contactsService, chatService, communityService,
|
result.appSearchModule = app_search_module.newModule(result, events, contactsService, chatService, communityService,
|
||||||
messageService)
|
messageService)
|
||||||
result.nodeSectionModule = node_section_module.newModule(result, events, settingsService, nodeService, nodeConfigurationService)
|
result.nodeSectionModule = node_section_module.newModule(result, events, settingsService, nodeService, nodeConfigurationService)
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import NimQml, Tables, chronicles, json, stint
|
import NimQml, Tables, chronicles, json, stint, strutils, strformat
|
||||||
import ../../../app/core/eventemitter
|
import ../../../app/core/eventemitter
|
||||||
import ../../../app/core/tasks/[qt, threadpool]
|
import ../../../app/core/tasks/[qt, threadpool]
|
||||||
|
|
||||||
import ../../../backend/community_tokens as tokens_backend
|
import ../../../backend/community_tokens as tokens_backend
|
||||||
import ../transaction/service as transaction_service
|
import ../transaction/service as transaction_service
|
||||||
|
import ../token/service as token_service
|
||||||
|
import ../settings/service as settings_service
|
||||||
import ../ens/utils as ens_utils
|
import ../ens/utils as ens_utils
|
||||||
import ../eth/dto/transaction
|
import ../eth/dto/transaction
|
||||||
|
|
||||||
|
@ -41,6 +43,8 @@ QtObject:
|
||||||
events: EventEmitter
|
events: EventEmitter
|
||||||
threadpool: ThreadPool
|
threadpool: ThreadPool
|
||||||
transactionService: transaction_service.Service
|
transactionService: transaction_service.Service
|
||||||
|
tokenService: token_service.Service
|
||||||
|
settingsService: settings_service.Service
|
||||||
|
|
||||||
proc delete*(self: Service) =
|
proc delete*(self: Service) =
|
||||||
self.QObject.delete
|
self.QObject.delete
|
||||||
|
@ -48,13 +52,17 @@ QtObject:
|
||||||
proc newService*(
|
proc newService*(
|
||||||
events: EventEmitter,
|
events: EventEmitter,
|
||||||
threadpool: ThreadPool,
|
threadpool: ThreadPool,
|
||||||
transactionService: transaction_service.Service
|
transactionService: transaction_service.Service,
|
||||||
|
tokenService: token_service.Service,
|
||||||
|
settingsService: settings_service.Service
|
||||||
): Service =
|
): Service =
|
||||||
result = Service()
|
result = Service()
|
||||||
result.QObject.setup
|
result.QObject.setup
|
||||||
result.events = events
|
result.events = events
|
||||||
result.threadpool = threadpool
|
result.threadpool = threadpool
|
||||||
result.transactionService = transactionService
|
result.transactionService = transactionService
|
||||||
|
result.tokenService = tokenService
|
||||||
|
result.settingsService = settingsService
|
||||||
|
|
||||||
proc init*(self: Service) =
|
proc init*(self: Service) =
|
||||||
self.events.on(PendingTransactionTypeDto.CollectibleDeployment.event) do(e: Args):
|
self.events.on(PendingTransactionTypeDto.CollectibleDeployment.event) do(e: Args):
|
||||||
|
@ -139,3 +147,12 @@ QtObject:
|
||||||
if token.symbol == symbol:
|
if token.symbol == symbol:
|
||||||
return token
|
return token
|
||||||
|
|
||||||
|
proc getFiatValue*(self: Service, cryptoBalance: string, cryptoSymbol: string): string =
|
||||||
|
if (cryptoBalance == "" or cryptoSymbol == ""):
|
||||||
|
return "0.00"
|
||||||
|
|
||||||
|
let currentCurrency = self.settingsService.getCurrency()
|
||||||
|
|
||||||
|
let price = self.tokenService.getTokenPrice(cryptoSymbol, currentCurrency)
|
||||||
|
let value = parseFloat(cryptoBalance) * price
|
||||||
|
return fmt"{value:.2f}"
|
|
@ -47,7 +47,7 @@ SettingsPageLayout {
|
||||||
string accountName,
|
string accountName,
|
||||||
string accountAddress)
|
string accountAddress)
|
||||||
|
|
||||||
signal signMintTransactionOpened
|
signal signMintTransactionOpened(int chainId)
|
||||||
|
|
||||||
function navigateBack() {
|
function navigateBack() {
|
||||||
stackManager.pop(StackView.Immediate)
|
stackManager.pop(StackView.Immediate)
|
||||||
|
@ -223,7 +223,7 @@ SettingsPageLayout {
|
||||||
feeText: root.feeText
|
feeText: root.feeText
|
||||||
isFeeLoading: root.isFeeLoading
|
isFeeLoading: root.isFeeLoading
|
||||||
|
|
||||||
onOpened: root.signMintTransactionOpened()
|
onOpened: root.signMintTransactionOpened(parent.chainId)
|
||||||
onCancelClicked: close()
|
onCancelClicked: close()
|
||||||
onSignTransactionClicked: parent.signMintTransaction()
|
onSignTransactionClicked: parent.signMintTransaction()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ QtObject {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property var communityTokensModuleInst: communityTokensModule ?? null
|
property var communityTokensModuleInst: communityTokensModule ?? null
|
||||||
property string deployFee: "0.0015 ETH ($75.34)"//communityTokensModuleInst.computeFee // TODO: Backend
|
property string deployFee: communityTokensModuleInst.deployFee
|
||||||
|
|
||||||
// Network selection properties:
|
// Network selection properties:
|
||||||
property var layer1Networks: networksModule.layer1
|
property var layer1Networks: networksModule.layer1
|
||||||
|
@ -60,9 +60,10 @@ QtObject {
|
||||||
infiniteSupply, transferable, selfDestruct, chainId, artworkSource)
|
infiniteSupply, transferable, selfDestruct, chainId, artworkSource)
|
||||||
}
|
}
|
||||||
|
|
||||||
function computeDeployFee() {
|
function computeDeployFee(chainId) {
|
||||||
// TODO: Backend compute minitng fee
|
// TODO this call will be async
|
||||||
root.deployFeeUpdated(root.deployFee) // TO BE REMOVED
|
communityTokensModuleInst.computeDeployFee(chainId)
|
||||||
|
root.deployFeeUpdated(root.deployFee)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Airdrop tokens:
|
// Airdrop tokens:
|
||||||
|
|
|
@ -300,7 +300,7 @@ StatusSectionLayout {
|
||||||
accounts: root.rootStore.accounts
|
accounts: root.rootStore.accounts
|
||||||
|
|
||||||
onPreviousPageNameChanged: root.backButtonName = previousPageName
|
onPreviousPageNameChanged: root.backButtonName = previousPageName
|
||||||
onSignMintTransactionOpened: communityTokensStore.computeDeployFee()
|
onSignMintTransactionOpened: communityTokensStore.computeDeployFee(chainId)
|
||||||
onMintCollectible: {
|
onMintCollectible: {
|
||||||
communityTokensStore.deployCollectible(root.community.id,
|
communityTokensStore.deployCollectible(root.community.id,
|
||||||
accountAddress,
|
accountAddress,
|
||||||
|
@ -326,11 +326,16 @@ StatusSectionLayout {
|
||||||
Connections {
|
Connections {
|
||||||
target: rootStore.communityTokensStore
|
target: rootStore.communityTokensStore
|
||||||
function onDeployFeeUpdated(value) {
|
function onDeployFeeUpdated(value) {
|
||||||
|
// TODO better error handling
|
||||||
|
if (value === "-") {
|
||||||
|
mintPanel.isFeeLoading = true
|
||||||
|
} else {
|
||||||
mintPanel.isFeeLoading = false
|
mintPanel.isFeeLoading = false
|
||||||
mintPanel.feeText = value
|
mintPanel.feeText = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CommunityAirdropsSettingsPanel {
|
CommunityAirdropsSettingsPanel {
|
||||||
readonly property CommunityTokensStore communityTokensStore:
|
readonly property CommunityTokensStore communityTokensStore:
|
||||||
|
|
Loading…
Reference in New Issue