Skip to content

Commit 6f0f165

Browse files
committed
refactor(SwapModal): Remove Global Swap Launch Signal in Favor of Scoped Handler
Eliminated the use of the `Global` signal to initiate `Swap`. Replaced it with a context-specific handler to improve modularity and reduce global coupling.
1 parent d9a4923 commit 6f0f165

File tree

5 files changed

+16
-22
lines changed

5 files changed

+16
-22
lines changed

ui/app/AppLayouts/Wallet/WalletLayout.qml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ Item {
5757
signal sendTokenRequested(string senderAddress, string tokenId, int tokenType)
5858
signal bridgeTokenRequested(string tokenId, int tokenType)
5959

60+
signal openSwapModalRequested(var swapFormData)
61+
6062
onAppMainVisibleChanged: {
6163
resetView()
6264
}
@@ -258,11 +260,7 @@ Item {
258260
d.swapFormData.selectedAccountAddress = d.getSelectedOrFirstNonWatchedAddress()
259261
d.swapFormData.selectedNetworkChainId = StatusQUtils.ModelUtils.getByKey(root.networksStore.activeNetworks, "layer", 1, "chainId")
260262
d.swapFormData.fromTokensKey = tokensKey
261-
Global.openSwapModalRequested(d.swapFormData, (popup) => {
262-
popup.Component.destruction.connect(() => {
263-
d.swapFormData.resetFormData()
264-
})
265-
})
263+
root.openSwapModalRequested(d.swapFormData)
266264
}
267265
onDappListRequested: root.dappListRequested()
268266
onDappConnectRequested: root.dappConnectRequested()
@@ -391,11 +389,7 @@ Item {
391389
if(!!walletStore.currentViewedHoldingTokensKey && walletStore.currentViewedHoldingType === Constants.TokenType.ERC20) {
392390
d.swapFormData.fromTokensKey = walletStore.currentViewedHoldingTokensKey
393391
}
394-
Global.openSwapModalRequested(d.swapFormData, (popup) => {
395-
popup.Component.destruction.connect(() => {
396-
d.swapFormData.resetFormData()
397-
})
398-
})
392+
root.openSwapModalRequested(d.swapFormData)
399393
}
400394
onLaunchBuyCryptoModal: d.launchBuyCryptoModal()
401395

ui/app/mainui/AppMain.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,7 @@ Item {
19861986
onBridgeTokenRequested: (tokenId, tokenType) => {
19871987
popupRequestsHandler.sendModalHandler.bridgeToken(tokenId, tokenType)
19881988
}
1989+
onOpenSwapModalRequested: popupRequestsHandler.swapModalHandler.launchSwapSpecific(swapFormData)
19891990
}
19901991
onLoaded: {
19911992
item.resetView()

ui/app/mainui/Handlers/HandlersManager.qml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,17 @@ QtObject {
4545
SQUtils.ModelUtils.get(root.walletRootStore.nonWatchAccounts, 0, "address")
4646
swapFormData.selectedNetworkChainId =
4747
SQUtils.ModelUtils.getByKey(root.networksStore.activeNetworks, "layer", 1, "chainId")
48-
Global.openSwapModalRequested(swapFormData, (popup) => {
49-
popup.Component.destruction.connect(() => {
50-
swapFormData.resetFormData()
51-
})})
48+
openSendModal(swapFormData, (popup) => {
49+
popup.Component.destruction.connect(() => {
50+
swapFormData.resetFormData()
51+
})})
52+
}
53+
54+
function launchSwapSpecific(data) {
55+
openSendModal(data, (popup) => {
56+
popup.Component.destruction.connect(() => {
57+
data.resetFormData()
58+
})})
5259
}
5360

5461
popupParent: root.popupParent

ui/app/mainui/Handlers/SwapModalHandler.qml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ QtObject {
1818
required property WalletStores.WalletAssetsStore walletAssetsStore
1919
required property NetworksStore networksStore
2020

21-
Component.onCompleted: {
22-
// TODO update opening logic to be similar to send
23-
Global.openSwapModalRequested.connect(openSendModal)
24-
}
25-
2621
function openSendModal(params = {}, callback = null) {
2722
d.swapInputParams = params
2823
let swapModalInst = swapModalComponent.createObject(popupParent)

ui/imports/utils/Global.qml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ QtObject {
9292

9393
signal openNewsMessagePopupRequested(var notification, string notificationId)
9494

95-
// Swap
96-
signal openSwapModalRequested(var formDataParams, var callback)
97-
9895
// BuyCrypto
9996
signal openBuyCryptoModalRequested(var formDataParams)
10097

0 commit comments

Comments
 (0)