mirror of
https://github.com/status-im/status-go.git
synced 2025-02-16 16:56:53 +00:00
feat(wallet): add Wallet Connect state change API
Updates status-desktop #12858
This commit is contained in:
parent
317ad2f906
commit
99f4d621e0
@ -27,6 +27,7 @@ import (
|
|||||||
"github.com/status-im/status-go/services/wallet/thirdparty"
|
"github.com/status-im/status-go/services/wallet/thirdparty"
|
||||||
"github.com/status-im/status-go/services/wallet/token"
|
"github.com/status-im/status-go/services/wallet/token"
|
||||||
"github.com/status-im/status-go/services/wallet/transfer"
|
"github.com/status-im/status-go/services/wallet/transfer"
|
||||||
|
"github.com/status-im/status-go/services/wallet/walletconnect"
|
||||||
wc "github.com/status-im/status-go/services/wallet/walletconnect"
|
wc "github.com/status-im/status-go/services/wallet/walletconnect"
|
||||||
"github.com/status-im/status-go/services/wallet/walletevent"
|
"github.com/status-im/status-go/services/wallet/walletevent"
|
||||||
"github.com/status-im/status-go/transactions"
|
"github.com/status-im/status-go/transactions"
|
||||||
@ -681,7 +682,7 @@ func (api *API) WCPairSessionProposal(ctx context.Context, sessionProposalJSON s
|
|||||||
return api.s.walletConnect.PairSessionProposal(data)
|
return api.s.walletConnect.PairSessionProposal(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WCPairEstablished confirms that a pairing has been established
|
// WCRecordSuccessfulPairing confirms that a pairing has been established
|
||||||
func (api *API) WCRecordSuccessfulPairing(ctx context.Context, sessionProposalJSON string) error {
|
func (api *API) WCRecordSuccessfulPairing(ctx context.Context, sessionProposalJSON string) error {
|
||||||
log.Debug("wallet.api.wc.RecordSuccessfulPairing", "proposal.len", len(sessionProposalJSON))
|
log.Debug("wallet.api.wc.RecordSuccessfulPairing", "proposal.len", len(sessionProposalJSON))
|
||||||
|
|
||||||
@ -694,7 +695,13 @@ func (api *API) WCRecordSuccessfulPairing(ctx context.Context, sessionProposalJS
|
|||||||
return api.s.walletConnect.RecordSuccessfulPairing(data)
|
return api.s.walletConnect.RecordSuccessfulPairing(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WCSessionRequest responds to "session_request" event
|
// WCChangePairingState changes the active state of a pairing
|
||||||
|
func (api *API) WCChangePairingState(ctx context.Context, topic walletconnect.Topic, active bool) error {
|
||||||
|
log.Debug("wallet.api.wc.ChangePairingState", "topic", topic, "active", active)
|
||||||
|
|
||||||
|
return api.s.walletConnect.ChangePairingState(topic, active)
|
||||||
|
}
|
||||||
|
|
||||||
func (api *API) WCHasActivePairings(ctx context.Context) (bool, error) {
|
func (api *API) WCHasActivePairings(ctx context.Context) (bool, error) {
|
||||||
log.Debug("wallet.api.wc.HasActivePairings")
|
log.Debug("wallet.api.wc.HasActivePairings")
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package walletconnect
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Pairing struct {
|
type Pairing struct {
|
||||||
@ -22,6 +23,25 @@ func InsertPairing(db *sql.DB, pairing Pairing) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ChangePairingState(db *sql.DB, topic Topic, active bool) error {
|
||||||
|
stmt, err := db.Prepare("UPDATE wallet_connect_pairings SET active = ? WHERE topic = ?")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := stmt.Exec(active, topic)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
rowsAffected, err := res.RowsAffected()
|
||||||
|
if rowsAffected == 0 {
|
||||||
|
return errors.New("unable to locate pairing entry for DB state change")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func GetPairingByTopic(db *sql.DB, topic Topic) (*Pairing, error) {
|
func GetPairingByTopic(db *sql.DB, topic Topic) (*Pairing, error) {
|
||||||
querySQL := `SELECT topic, expiry_timestamp, active, app_name, url, description, icon, verified_is_scam, verified_origin, verified_verify_url, verified_validation FROM wallet_connect_pairings WHERE topic = ?`
|
querySQL := `SELECT topic, expiry_timestamp, active, app_name, url, description, icon, verified_is_scam, verified_origin, verified_verify_url, verified_validation FROM wallet_connect_pairings WHERE topic = ?`
|
||||||
|
|
||||||
|
@ -66,6 +66,23 @@ func TestInsertAndGetPairing(t *testing.T) {
|
|||||||
require.Equal(t, entry, *retrievedPairing)
|
require.Equal(t, entry, *retrievedPairing)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestChangePairingState(t *testing.T) {
|
||||||
|
db, close := setupTestDB(t)
|
||||||
|
defer close()
|
||||||
|
|
||||||
|
entry := generateTestData(1)[0]
|
||||||
|
err := InsertPairing(db, entry)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
err = ChangePairingState(db, entry.Topic, false)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
retrievedPairing, err := GetPairingByTopic(db, entry.Topic)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.Equal(t, false, retrievedPairing.Active)
|
||||||
|
}
|
||||||
|
|
||||||
func TestGet(t *testing.T) {
|
func TestGet(t *testing.T) {
|
||||||
db, close := setupTestDB(t)
|
db, close := setupTestDB(t)
|
||||||
defer close()
|
defer close()
|
||||||
|
@ -112,7 +112,7 @@ func (s *Service) buildTransaction(request SessionRequest) (response *SessionReq
|
|||||||
Address: account.Address,
|
Address: account.Address,
|
||||||
AddressPath: account.Path,
|
AddressPath: account.Path,
|
||||||
SignOnKeycard: kp.MigratedToKeycard(),
|
SignOnKeycard: kp.MigratedToKeycard(),
|
||||||
MesageToSign: signer.Hash(txBeingSigned),
|
MessageToSign: signer.Hash(txBeingSigned),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,6 +183,6 @@ func (s *Service) buildMessage(request SessionRequest, addressIndex int, message
|
|||||||
Address: account.Address,
|
Address: account.Address,
|
||||||
AddressPath: account.Path,
|
AddressPath: account.Path,
|
||||||
SignOnKeycard: kp.MigratedToKeycard(),
|
SignOnKeycard: kp.MigratedToKeycard(),
|
||||||
MesageToSign: types.HexBytes(hash),
|
MessageToSign: types.HexBytes(hash),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -200,6 +200,10 @@ func (s *Service) RecordSuccessfulPairing(proposal SessionProposal) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Service) ChangePairingState(topic Topic, active bool) error {
|
||||||
|
return ChangePairingState(s.db, topic, active)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Service) HasActivePairings() (bool, error) {
|
func (s *Service) HasActivePairings() (bool, error) {
|
||||||
return HasActivePairings(s.db, time.Now().Unix())
|
return HasActivePairings(s.db, time.Now().Unix())
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ type SessionRequestResponse struct {
|
|||||||
Address types.Address `json:"address,omitempty"`
|
Address types.Address `json:"address,omitempty"`
|
||||||
AddressPath string `json:"addressPath,omitempty"`
|
AddressPath string `json:"addressPath,omitempty"`
|
||||||
SignOnKeycard bool `json:"signOnKeycard,omitempty"`
|
SignOnKeycard bool `json:"signOnKeycard,omitempty"`
|
||||||
MesageToSign interface{} `json:"messageToSign,omitempty"`
|
MessageToSign interface{} `json:"messageToSign,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Valid namespace
|
// Valid namespace
|
||||||
|
Loading…
x
Reference in New Issue
Block a user