Skip to content

Commit

Permalink
chore: align sending flow for stickers with the new sending flow
Browse files Browse the repository at this point in the history
Based on changes done in this PR status-im/status-go#5807
we can simplify our client logic a lot.

This results in the removal of many lines of code that are no longer needed

Closes 1st part of #16336
  • Loading branch information
saledjenic committed Sep 25, 2024
1 parent aad983a commit ded1408
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 524 deletions.
2 changes: 1 addition & 1 deletion src/app/modules/main/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ proc newModule*[T](
networkService, keycardService, keychainService, tokenService, nodeService
)
result.stickersModule = stickers_module.newModule(result, events, stickersService, settingsService, walletAccountService,
networkService, tokenService, keycardService)
networkService, tokenService)
result.gifsModule = gifs_module.newModule(result, events, gifService)
result.activityCenterModule = activity_center_module.newModule(result, events, activityCenterService, contactsService,
messageService, chatService, communityService)
Expand Down
73 changes: 4 additions & 69 deletions src/app/modules/main/stickers/controller.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Tables, uuids, stint, json
import Tables, uuids, stint

import ./io_interface

Expand All @@ -7,14 +7,8 @@ import app_service/service/stickers/service as stickers_service
import app_service/service/token/service
import app_service/service/settings/service as settings_service
import app_service/service/network/service as network_service
import app_service/service/eth/utils as eth_utils
import app_service/service/wallet_account/service as wallet_account_service
import app_service/service/token/service as token_service
import app_service/service/keycard/service as keycard_service
import app/modules/shared_modules/keycard_popup/io_interface as keycard_shared_module
import app_service/service/network/network_item

const UNIQUE_BUY_STICKER_TRANSACTION_MODULE_IDENTIFIER* = "StickersSection-TransactionModule"

type
Controller* = ref object of RootObj
Expand All @@ -25,7 +19,6 @@ type
networkService: network_service.Service
walletAccountService: wallet_account_service.Service
tokenService: token_service.Service
keycardService: keycard_service.Service
connectionKeycardResponse: UUID
disconnected: bool

Expand All @@ -37,7 +30,6 @@ proc newController*(
walletAccountService: wallet_account_service.Service,
networkService: network_service.Service,
tokenService: token_service.Service,
keycardService: keycard_service.Service
): Controller =
result = Controller()
result.delegate = delegate
Expand All @@ -47,7 +39,6 @@ proc newController*(
result.networkService = networkService
result.walletAccountService = walletAccountService
result.tokenService = tokenService
result.keycardService = keycardService
result.disconnected = false

proc delete*(self: Controller) =
Expand Down Expand Up @@ -81,9 +72,9 @@ proc init*(self: Controller) =
self.events.on(SIGNAL_ALL_STICKER_PACKS_LOAD_FAILED) do(e: Args):
self.delegate.allPacksLoadFailed()

self.events.on(SIGNAL_STICKER_GAS_ESTIMATED) do(e: Args):
let args = StickerGasEstimatedArgs(e)
self.delegate.gasEstimateReturned(args.estimate, args.uuid)
self.events.on(SIGNAL_STICKER_TRANSACTION_SENT) do(e:Args):
let args = StickerBuyResultArgs(e)
self.delegate.stickerTransactionSent(args.chainId, args.packId, args.txHash, args.error)

self.events.on(SIGNAL_STICKER_TRANSACTION_CONFIRMED) do(e:Args):
let args = StickerTransactionArgs(e)
Expand All @@ -93,28 +84,10 @@ proc init*(self: Controller) =
let args = StickerTransactionArgs(e)
self.delegate.stickerTransactionReverted(args.transactionType, args.packID, args.transactionHash)

self.events.on(SIGNAL_SHARED_KEYCARD_MODULE_USER_AUTHENTICATED) do(e: Args):
let args = SharedKeycarModuleArgs(e)
if args.uniqueIdentifier != UNIQUE_BUY_STICKER_TRANSACTION_MODULE_IDENTIFIER:
return
self.delegate.onKeypairAuthenticated(args.password, args.pin)

self.events.on(SIGNAL_STICKER_PACK_INSTALLED) do(e: Args):
let args = StickerPackInstalledArgs(e)
self.delegate.onStickerPackInstalled(args.packId)

proc prepareTxForBuyingStickers*(self: Controller, chainId: int, packId: string, address: string, gas: string, gasPrice: string,
maxPriorityFeePerGas: string, maxFeePerGas: string, eip1559Enabled: bool): JsonNode =
return self.stickerService.prepareTxForBuyingStickers(chainId, packId, address, gas, gasPrice, maxPriorityFeePerGas,
maxFeePerGas, eip1559Enabled)

proc signBuyingStickersTxLocally*(self: Controller, data, account, hashedPasssword: string): string =
return self.stickerService.signBuyingStickersTxLocally(data, account, hashedPasssword)

proc sendBuyingStickersTxWithSignatureAndWatch*(self: Controller, chainId: int, txData: JsonNode, packId: string,
signature: string): StickerBuyResultArgs =
return self.stickerService.sendBuyingStickersTxWithSignatureAndWatch(chainId, txData, packId, signature)

proc getRecentStickers*(self: Controller): seq[StickerDto] =
return self.stickerService.getRecentStickers()

Expand All @@ -124,9 +97,6 @@ proc loadRecentStickers*(self: Controller) =
proc loadInstalledStickerPacks*(self: Controller) =
self.stickerService.asyncLoadInstalledStickerPacks()

proc estimate*(self: Controller, packId: string, address: string, price: string, uuid: string) =
self.stickerService.estimate(packId, address, price, uuid)

proc getInstalledStickerPacks*(self: Controller): Table[string, StickerPackDto] =
self.stickerService.getInstalledStickerPacks()

Expand All @@ -153,9 +123,6 @@ proc sendSticker*(
preferredUsername: string) =
self.stickerService.asyncSendSticker(channelId, replyTo, sticker, preferredUsername)

proc wei2Eth*(self: Controller, price: Stuint[256]): string =
eth_utils.wei2Eth(price)

proc getSigningPhrase*(self: Controller): string =
return self.settingsService.getSigningPhrase()

Expand All @@ -165,40 +132,8 @@ proc getStickerMarketAddress*(self: Controller): string =
proc getWalletDefaultAddress*(self: Controller): string =
return self.walletAccountService.getWalletAccount(0).address

proc getKeypairByAccountAddress*(self: Controller, address: string): KeypairDto =
return self.walletAccountService.getKeypairByAccountAddress(address)

proc getCurrentCurrency*(self: Controller): string =
return self.settingsService.getCurrency()

proc getAppNetwork*(self: Controller): NetworkItem =
return self.networkService.getAppNetwork()

proc getStatusTokenKey*(self: Controller): string =
return self.tokenService.getStatusTokenKey()

proc authenticate*(self: Controller, keyUid = "") =
let data = SharedKeycarModuleAuthenticationArgs(uniqueIdentifier: UNIQUE_BUY_STICKER_TRANSACTION_MODULE_IDENTIFIER,
keyUid: keyUid)
self.events.emit(SIGNAL_SHARED_KEYCARD_MODULE_AUTHENTICATE_USER, data)

proc disconnectKeycardReponseSignal(self: Controller) =
self.events.disconnect(self.connectionKeycardResponse)

proc connectKeycardReponseSignal(self: Controller) =
self.connectionKeycardResponse = self.events.onWithUUID(SIGNAL_KEYCARD_RESPONSE) do(e: Args):
let args = KeycardLibArgs(e)
self.disconnectKeycardReponseSignal()
let currentFlow = self.keycardService.getCurrentFlow()
if currentFlow != KCSFlowType.Sign:
self.delegate.onTransactionSigned("", KeycardEvent())
return
self.delegate.onTransactionSigned(args.flowType, args.flowEvent)

proc cancelCurrentFlow*(self: Controller) =
self.keycardService.cancelCurrentFlow()

proc runSignFlow*(self: Controller, pin, bip44Path, txHash: string) =
self.cancelCurrentFlow()
self.connectKeycardReponseSignal()
self.keycardService.startSignFlow(bip44Path, txHash, pin)
24 changes: 5 additions & 19 deletions src/app/modules/main/stickers/io_interface.nim
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Tables, stint
import Tables
import ./item

import app_service/service/stickers/service as stickers_service
from app_service/service/keycard/service import KeycardEvent

type
AccessInterface* {.pure inheritable.} = ref object of RootObj
Expand All @@ -20,9 +19,6 @@ method isLoaded*(self: AccessInterface): bool {.base.} =
method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

method authenticateAndBuy*(self: AccessInterface, packId: string, address: string, gas: string, gasPrice: string, maxPriorityFeePerGas: string, maxFeePerGas: string, eip1559Enabled: bool){.base.} =
raise newException(ValueError, "No implementation available")

method getRecentStickers*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

Expand Down Expand Up @@ -68,8 +64,6 @@ method onStickerPackInstalled*(self: AccessInterface, packId: string) {.base.} =
method uninstallStickerPack*(self: AccessInterface, packId: string) {.base.} =
raise newException(ValueError, "No implementation available")

method wei2Eth*(self: AccessInterface, price: Stuint[256]): string {.base.} =
raise newException(ValueError, "No implementation available")

method removeRecentStickers*(self: AccessInterface, packId: string) {.base.} =
raise newException(ValueError, "No implementation available")
Expand All @@ -80,9 +74,6 @@ method sendSticker*(self: AccessInterface, channelId: string, replyTo: string, s
method populateInstalledStickerPacks*(self: AccessInterface, stickers: Table[string, StickerPackDto]) {.base.} =
raise newException(ValueError, "No implementation available")

method gasEstimateReturned*(self: AccessInterface, estimate: int, uuid: string) {.base.} =
raise newException(ValueError, "No implementation available")

method addStickerPackToList*(self: AccessInterface, stickerPack: StickerPackDto, isInstalled: bool, isBought: bool, isPending: bool) {.base.} =
raise newException(ValueError, "No implementation available")

Expand All @@ -92,20 +83,15 @@ method getWalletDefaultAddress*(self: AccessInterface): string {.base.} =
method getCurrentCurrency*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available")

method getGasEthValue*(self: AccessInterface, gweiValue: string, gasLimit: string): string {.base.} =
raise newException(ValueError, "No implementation available")

method getStatusTokenKey*(self: AccessInterface): string {.base.} =
raise newException(ValueError, "No implementation available")

method stickerTransactionConfirmed*(self: AccessInterface, trxType: string, packID: string, transactionHash: string) {.base.} =
method stickerTransactionSent*(self: AccessInterface, chainId: int, packId: string, txHash: string, error: string) {.base.} =
raise newException(ValueError, "No implementation available")

method stickerTransactionReverted*(self: AccessInterface, trxType: string, packID: string, transactionHash: string) {.base.} =
raise newException(ValueError, "No implementation available")

method onKeypairAuthenticated*(self: AccessInterface, password: string, pin: string) {.base.} =
method stickerTransactionConfirmed*(self: AccessInterface, trxType: string, packID: string, transactionHash: string) {.base.} =
raise newException(ValueError, "No implementation available")

method onTransactionSigned*(self: AccessInterface, keycardFlowType: string, keycardEvent: KeycardEvent) {.base.} =
raise newException(ValueError, "No implementation available")
method stickerTransactionReverted*(self: AccessInterface, trxType: string, packID: string, transactionHash: string) {.base.} =
raise newException(ValueError, "No implementation available")
6 changes: 4 additions & 2 deletions src/app/modules/main/stickers/models/sticker_pack_list.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import NimQml, Tables, sequtils, sugar
import ./sticker_list
import ../io_interface, ../item
# TODO remove those uses of services stuff
import ../../../../../app_service/service/eth/utils as eth_utils
import app_service/service/eth/utils as eth_utils
import app_service/common/conversion as service_conversion


type
StickerPackRoles {.pure.} = enum
Expand Down Expand Up @@ -57,7 +59,7 @@ QtObject:
of StickerPackRoles.Author: result = newQVariant(stickerPack.author)
of StickerPackRoles.Id: result = newQVariant(stickerPack.id)
of StickerPackRoles.Name: result = newQVariant(stickerPack.name)
of StickerPackRoles.Price: result = newQVariant(self.delegate.wei2Eth(stickerPack.price))
of StickerPackRoles.Price: result = newQVariant(service_conversion.wei2Eth(stickerPack.price))
of StickerPackRoles.Preview: result = newQVariant(stickerPack.preview)
of StickerPackRoles.Stickers: result = newQVariant(packInfo.stickers)
of StickerPackRoles.Thumbnail: result = newQVariant(stickerPack.thumbnail)
Expand Down
Loading

0 comments on commit ded1408

Please sign in to comment.