mirror of
https://github.com/status-im/status-go.git
synced 2025-02-20 18:58:14 +00:00
feat_: wallet connect session notification
Signed-off-by: yqrashawn <namy.19@gmail.com>
This commit is contained in:
parent
b329b158c8
commit
9dbfb9eccd
@ -2706,6 +2706,10 @@ func (b *GethStatusBackend) injectAccountsIntoWakuService(w types.WakuKeyManager
|
|||||||
b.statusNode.ChatService(accDB).Init(messenger)
|
b.statusNode.ChatService(accDB).Init(messenger)
|
||||||
b.statusNode.EnsService().Init(messenger.SyncEnsNamesWithDispatchMessage)
|
b.statusNode.EnsService().Init(messenger.SyncEnsNamesWithDispatchMessage)
|
||||||
b.statusNode.CommunityTokensService().Init(messenger)
|
b.statusNode.CommunityTokensService().Init(messenger)
|
||||||
|
|
||||||
|
if walletService := b.statusNode.WalletService(); walletService != nil {
|
||||||
|
walletService.InjectMessenger(messenger)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -42,6 +42,8 @@ const (
|
|||||||
ActivityCenterNotificationTypeCommunityUnbanned
|
ActivityCenterNotificationTypeCommunityUnbanned
|
||||||
ActivityCenterNotificationTypeNewInstallationReceived
|
ActivityCenterNotificationTypeNewInstallationReceived
|
||||||
ActivityCenterNotificationTypeNewInstallationCreated
|
ActivityCenterNotificationTypeNewInstallationCreated
|
||||||
|
ActivityCenterNotificationTypeDAppConnected
|
||||||
|
ActivityCenterNotificationTypeDAppDisconnected
|
||||||
)
|
)
|
||||||
|
|
||||||
type ActivityCenterMembershipStatus int
|
type ActivityCenterMembershipStatus int
|
||||||
@ -103,8 +105,12 @@ type ActivityCenterNotification struct {
|
|||||||
TokenData *ActivityTokenData `json:"tokenData"`
|
TokenData *ActivityTokenData `json:"tokenData"`
|
||||||
//Used for synchronization. Each update should increment the UpdatedAt.
|
//Used for synchronization. Each update should increment the UpdatedAt.
|
||||||
//The value should represent the time when the update occurred.
|
//The value should represent the time when the update occurred.
|
||||||
UpdatedAt uint64 `json:"updatedAt"`
|
UpdatedAt uint64 `json:"updatedAt"`
|
||||||
AlbumMessages []*common.Message `json:"albumMessages"`
|
AlbumMessages []*common.Message `json:"albumMessages"`
|
||||||
|
WalletProviderSessionTopic string `json:"walletProviderSessionTopic"`
|
||||||
|
DAppURL string `json:"dappURL,omitempty"`
|
||||||
|
DAppName string `json:"dappName,omitempty"`
|
||||||
|
DAppIconURL string `json:"dappIconURL,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *ActivityCenterNotification) IncrementUpdatedAt(timesource common.TimeSource) {
|
func (n *ActivityCenterNotification) IncrementUpdatedAt(timesource common.TimeSource) {
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const allFieldsForTableActivityCenterNotification = `id, timestamp, notification_type, chat_id, read, dismissed, accepted, message, author,
|
const allFieldsForTableActivityCenterNotification = `id, timestamp, notification_type, chat_id, read, dismissed, accepted, message, author,
|
||||||
reply_message, community_id, membership_status, contact_verification_status, token_data, deleted, updated_at`
|
reply_message, community_id, membership_status, contact_verification_status, token_data, wallet_provider_session_topic, dapp_url, dapp_name, dapp_icon_url, deleted, updated_at`
|
||||||
|
|
||||||
var emptyNotifications = make([]*ActivityCenterNotification, 0)
|
var emptyNotifications = make([]*ActivityCenterNotification, 0)
|
||||||
|
|
||||||
@ -147,11 +147,15 @@ func (db sqlitePersistence) SaveActivityCenterNotification(notification *Activit
|
|||||||
accepted,
|
accepted,
|
||||||
dismissed,
|
dismissed,
|
||||||
token_data,
|
token_data,
|
||||||
|
wallet_provider_session_topic,
|
||||||
|
dapp_url,
|
||||||
|
dapp_name,
|
||||||
|
dapp_icon_url,
|
||||||
deleted,
|
deleted,
|
||||||
updated_at,
|
updated_at,
|
||||||
installation_id
|
installation_id
|
||||||
)
|
)
|
||||||
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
||||||
`,
|
`,
|
||||||
notification.ID,
|
notification.ID,
|
||||||
notification.Timestamp,
|
notification.Timestamp,
|
||||||
@ -167,6 +171,10 @@ func (db sqlitePersistence) SaveActivityCenterNotification(notification *Activit
|
|||||||
notification.Accepted,
|
notification.Accepted,
|
||||||
notification.Dismissed,
|
notification.Dismissed,
|
||||||
encodedTokenData,
|
encodedTokenData,
|
||||||
|
notification.WalletProviderSessionTopic,
|
||||||
|
notification.DAppURL,
|
||||||
|
notification.DAppName,
|
||||||
|
notification.DAppIconURL,
|
||||||
notification.Deleted,
|
notification.Deleted,
|
||||||
notification.UpdatedAt,
|
notification.UpdatedAt,
|
||||||
notification.InstallationID,
|
notification.InstallationID,
|
||||||
@ -213,6 +221,10 @@ func (db sqlitePersistence) parseRowFromTableActivityCenterNotification(rows *sq
|
|||||||
¬ification.MembershipStatus,
|
¬ification.MembershipStatus,
|
||||||
¬ification.ContactVerificationStatus,
|
¬ification.ContactVerificationStatus,
|
||||||
&tokenDataBytes,
|
&tokenDataBytes,
|
||||||
|
¬ification.WalletProviderSessionTopic,
|
||||||
|
¬ification.DAppURL,
|
||||||
|
¬ification.DAppName,
|
||||||
|
¬ification.DAppIconURL,
|
||||||
¬ification.Deleted,
|
¬ification.Deleted,
|
||||||
¬ification.UpdatedAt,
|
¬ification.UpdatedAt,
|
||||||
)
|
)
|
||||||
@ -291,9 +303,12 @@ func (db sqlitePersistence) unmarshalActivityCenterNotificationRow(row *sql.Row)
|
|||||||
&name,
|
&name,
|
||||||
&author,
|
&author,
|
||||||
&tokenDataBytes,
|
&tokenDataBytes,
|
||||||
|
¬ification.WalletProviderSessionTopic,
|
||||||
|
¬ification.DAppURL,
|
||||||
|
¬ification.DAppName,
|
||||||
|
¬ification.DAppIconURL,
|
||||||
¬ification.UpdatedAt,
|
¬ification.UpdatedAt,
|
||||||
&installationID,
|
&installationID)
|
||||||
)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -387,6 +402,10 @@ func (db sqlitePersistence) unmarshalActivityCenterNotificationRows(rows *sql.Ro
|
|||||||
&name,
|
&name,
|
||||||
&author,
|
&author,
|
||||||
&tokenDataBytes,
|
&tokenDataBytes,
|
||||||
|
¬ification.WalletProviderSessionTopic,
|
||||||
|
¬ification.DAppURL,
|
||||||
|
¬ification.DAppName,
|
||||||
|
¬ification.DAppIconURL,
|
||||||
&latestCursor,
|
&latestCursor,
|
||||||
¬ification.UpdatedAt,
|
¬ification.UpdatedAt,
|
||||||
&installationID,
|
&installationID,
|
||||||
@ -554,6 +573,10 @@ func (db sqlitePersistence) buildActivityCenterQuery(tx *sql.Tx, params activity
|
|||||||
c.name,
|
c.name,
|
||||||
a.author,
|
a.author,
|
||||||
a.token_data,
|
a.token_data,
|
||||||
|
a.wallet_provider_session_topic,
|
||||||
|
a.dapp_url,
|
||||||
|
a.dapp_name,
|
||||||
|
a.dapp_icon_url,
|
||||||
substr('0000000000000000000000000000000000000000000000000000000000000000' || a.timestamp, -64, 64) || hex(a.id) as cursor,
|
substr('0000000000000000000000000000000000000000000000000000000000000000' || a.timestamp, -64, 64) || hex(a.id) as cursor,
|
||||||
a.updated_at,
|
a.updated_at,
|
||||||
a.installation_id
|
a.installation_id
|
||||||
@ -676,6 +699,10 @@ func (db sqlitePersistence) GetActivityCenterNotificationsByID(ids []types.HexBy
|
|||||||
c.name,
|
c.name,
|
||||||
a.author,
|
a.author,
|
||||||
a.token_data,
|
a.token_data,
|
||||||
|
a.wallet_provider_session_topic,
|
||||||
|
a.dapp_url,
|
||||||
|
a.dapp_name,
|
||||||
|
a.dapp_icon_url,
|
||||||
substr('0000000000000000000000000000000000000000000000000000000000000000' || a.timestamp, -64, 64) || hex(a.id) as cursor,
|
substr('0000000000000000000000000000000000000000000000000000000000000000' || a.timestamp, -64, 64) || hex(a.id) as cursor,
|
||||||
a.updated_at,
|
a.updated_at,
|
||||||
a.installation_id
|
a.installation_id
|
||||||
@ -718,6 +745,10 @@ func (db sqlitePersistence) GetActivityCenterNotificationByID(id types.HexBytes)
|
|||||||
c.name,
|
c.name,
|
||||||
a.author,
|
a.author,
|
||||||
a.token_data,
|
a.token_data,
|
||||||
|
a.wallet_provider_session_topic,
|
||||||
|
a.dapp_url,
|
||||||
|
a.dapp_name,
|
||||||
|
a.dapp_icon_url,
|
||||||
a.updated_at,
|
a.updated_at,
|
||||||
a.installation_id
|
a.installation_id
|
||||||
FROM activity_center_notifications a
|
FROM activity_center_notifications a
|
||||||
@ -1353,6 +1384,10 @@ func (db sqlitePersistence) ActiveContactRequestNotification(contactID string) (
|
|||||||
c.name,
|
c.name,
|
||||||
a.author,
|
a.author,
|
||||||
a.token_data,
|
a.token_data,
|
||||||
|
a.wallet_provider_session_topic,
|
||||||
|
a.dapp_url,
|
||||||
|
a.dapp_name,
|
||||||
|
a.dapp_icon_url,
|
||||||
a.updated_at,
|
a.updated_at,
|
||||||
a.installation_id
|
a.installation_id
|
||||||
FROM activity_center_notifications a
|
FROM activity_center_notifications a
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package protocol
|
package protocol
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/status-im/status-go/eth-node/types"
|
||||||
"github.com/status-im/status-go/protocol/requests"
|
"github.com/status-im/status-go/protocol/requests"
|
||||||
|
"github.com/status-im/status-go/services/wallet/walletconnect"
|
||||||
)
|
)
|
||||||
|
|
||||||
type WalletConnectSession struct {
|
type WalletConnectSession struct {
|
||||||
@ -30,6 +32,28 @@ func (m *Messenger) AddWalletConnectSession(request *requests.AddWalletConnectSe
|
|||||||
return m.persistence.InsertWalletConnectSession(session)
|
return m.persistence.InsertWalletConnectSession(session)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Messenger) NewWalletConnectV2SessionCreatedNotification(session walletconnect.Session) error {
|
||||||
|
now := m.GetCurrentTimeInMillis()
|
||||||
|
|
||||||
|
notification := &ActivityCenterNotification{
|
||||||
|
ID: types.FromHex(string(session.Topic) + "_dapp_connected"),
|
||||||
|
Type: ActivityCenterNotificationTypeDAppConnected,
|
||||||
|
DAppURL: session.Peer.Metadata.URL,
|
||||||
|
DAppName: session.Peer.Metadata.Name,
|
||||||
|
WalletProviderSessionTopic: string(session.Topic),
|
||||||
|
Timestamp: now,
|
||||||
|
UpdatedAt: now,
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(session.Peer.Metadata.Icons) > 0 {
|
||||||
|
notification.DAppIconURL = session.Peer.Metadata.Icons[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := m.persistence.SaveActivityCenterNotification(notification, true)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Messenger) GetWalletConnectSession() ([]WalletConnectSession, error) {
|
func (m *Messenger) GetWalletConnectSession() ([]WalletConnectSession, error) {
|
||||||
|
|
||||||
return m.getWalletConnectSession()
|
return m.getWalletConnectSession()
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
ALTER TABLE activity_center_notifications ADD COLUMN dapp_url TEXT NULL;
|
||||||
|
ALTER TABLE activity_center_notifications ADD COLUMN dapp_name TEXT NULL;
|
||||||
|
ALTER TABLE activity_center_notifications ADD COLUMN dapp_icon_url TEXT NULL;
|
||||||
|
ALTER TABLE activity_center_notifications ADD COLUMN wallet_provider_session_topic TEXT NULL;
|
@ -194,17 +194,17 @@ func (p *SessionProposal) ValidateProposal() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddSession adds a new active session to the database
|
// AddSession adds a new active session to the database
|
||||||
func AddSession(db *sql.DB, networks []params.Network, session_json string) error {
|
func AddSession(db *sql.DB, networks []params.Network, session_json string) (Session, error) {
|
||||||
var session Session
|
var session Session
|
||||||
err := json.Unmarshal([]byte(session_json), &session)
|
err := json.Unmarshal([]byte(session_json), &session)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unmarshal session: %v", err)
|
return session, fmt.Errorf("unmarshal session: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
chains := supportedChainsInSession(session)
|
chains := supportedChainsInSession(session)
|
||||||
testChains, err := areTestChains(networks, chains)
|
testChains, err := areTestChains(networks, chains)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("areTestChains: %v", err)
|
return session, fmt.Errorf("areTestChains: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rowEntry := DBSession{
|
rowEntry := DBSession{
|
||||||
@ -224,7 +224,7 @@ func AddSession(db *sql.DB, networks []params.Network, session_json string) erro
|
|||||||
rowEntry.IconURL = session.Peer.Metadata.Icons[0]
|
rowEntry.IconURL = session.Peer.Metadata.Icons[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
return UpsertSession(db, rowEntry)
|
return session, UpsertSession(db, rowEntry)
|
||||||
}
|
}
|
||||||
|
|
||||||
// areTestChains assumes chains to tests are all testnets or all mainnets
|
// areTestChains assumes chains to tests are all testnets or all mainnets
|
||||||
|
@ -395,7 +395,7 @@ func Test_AddSession(t *testing.T) {
|
|||||||
{ChainID: uint64(chainID), IsTest: true},
|
{ChainID: uint64(chainID), IsTest: true},
|
||||||
}
|
}
|
||||||
timestampBeforeAddSession := time.Now().Unix()
|
timestampBeforeAddSession := time.Now().Unix()
|
||||||
err := AddSession(db, networks, sessionJSON)
|
_, err := AddSession(db, networks, sessionJSON)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Validate that session was written correctly to the database
|
// Validate that session was written correctly to the database
|
||||||
|
Loading…
x
Reference in New Issue
Block a user