-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wallet) Wallet Connect session proposal implementation
Depends on status-go changes that implements Wallet Connect pair API Implement Controller to forward requests between status-go and SDK implementation in QML. Other changes: - Source Wallet Connect projectId from env vars - Mock controller in storybook Updates #12551
- Loading branch information
1 parent
d258b16
commit dda15da
Showing
21 changed files
with
602 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/app/modules/main/wallet_section/wallet_connect/controller.nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import NimQml, logging, json | ||
|
||
import backend/wallet_connect as backend | ||
|
||
import app/core/eventemitter | ||
import app/core/signals/types | ||
|
||
import constants | ||
|
||
QtObject: | ||
type | ||
Controller* = ref object of QObject | ||
events: EventEmitter | ||
|
||
proc setup(self: Controller) = | ||
self.QObject.setup | ||
|
||
proc delete*(self: Controller) = | ||
self.QObject.delete | ||
|
||
proc newController*(events: EventEmitter): Controller = | ||
new(result, delete) | ||
|
||
result.events = events | ||
|
||
result.setup() | ||
|
||
# Register for wallet events | ||
result.events.on(SignalType.Wallet.event, proc(e: Args) = | ||
# TODO #12434: async processing | ||
discard | ||
) | ||
|
||
# supportedNamespaces is a Namespace as defined in status-go: services/wallet/walletconnect/walletconnect.go | ||
proc proposeUserPair*(self: Controller, sessionProposalJson: string, supportedNamespacesJson: string) {.signal.} | ||
|
||
proc pairSessionProposal(self: Controller, sessionProposalJson: string) {.slot.} = | ||
let ok = backend.pair(sessionProposalJson, proc (res: JsonNode) = | ||
let sessionProposalJson = if res.hasKey("sessionProposal"): $res["sessionProposal"] else: "" | ||
let supportedNamespacesJson = if res.hasKey("supportedNamespaces"): $res["supportedNamespaces"] else: "" | ||
|
||
self.proposeUserPair(sessionProposalJson, supportedNamespacesJson) | ||
) | ||
|
||
if not ok: | ||
error "Failed to pair session" | ||
|
||
proc getProjectId*(self: Controller): string {.slot.} = | ||
return constants.WALLET_CONNECT_PROJECT_ID | ||
|
||
QtProperty[string] projectId: | ||
read = getProjectId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import options | ||
import json | ||
import core, response_type | ||
|
||
from gen import rpc | ||
import backend | ||
|
||
# Declared in services/wallet/walletconnect/walletconnect.go | ||
#const eventWCTODO*: string = "wallet-wc-todo" | ||
|
||
# Declared in services/wallet/walletconnect/walletconnect.go | ||
const ErrorChainsNotSupported*: string = "chains not supported" | ||
|
||
rpc(wCPairSessionProposal, "wallet"): | ||
sessionProposalJson: string | ||
|
||
# TODO #12434: async answer | ||
proc pair*(sessionProposalJson: string, callback: proc(response: JsonNode): void): bool = | ||
try: | ||
let response = wCPairSessionProposal(sessionProposalJson) | ||
if response.error == nil and response.result != nil: | ||
callback(response.result) | ||
return response.error == nil | ||
except Exception as e: | ||
echo "@dd wCPairSessionProposal response: ", e.msg | ||
return false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import QtQuick 2.15 | ||
import QtQuick.Controls 2.15 | ||
import QtQuick.Layouts 1.15 | ||
|
||
// Stub for Controller QObject defined in src/app/modules/main/wallet_section/wallet_connect/controller.nim | ||
Item { | ||
id: root | ||
|
||
signal proposeUserPair(string sessionProposalJson, string supportedNamespacesJson) | ||
|
||
// function pairSessionProposal(/*string*/ sessionProposalJson) | ||
required property var pairSessionProposal | ||
|
||
required property string projectId | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
WalletConnectController 1.0 WalletConnectController.qml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.