Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat_: dapp connected notification #5616

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/geth_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -2668,6 +2668,10 @@ func (b *GethStatusBackend) injectAccountsIntoWakuService(w types.WakuKeyManager
b.statusNode.ChatService(accDB).Init(messenger)
b.statusNode.EnsService().Init(messenger.SyncEnsNamesWithDispatchMessage)
b.statusNode.CommunityTokensService().Init(messenger)

if walletService := b.statusNode.WalletService(); walletService != nil {
walletService.InjectMessenger(messenger)
}
}

return nil
Expand Down
10 changes: 8 additions & 2 deletions protocol/activity_center.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const (
ActivityCenterNotificationTypeFirstCommunityTokenReceived
ActivityCenterNotificationTypeCommunityBanned
ActivityCenterNotificationTypeCommunityUnbanned
ActivityCenterNotificationTypeDAppConnected
ActivityCenterNotificationTypeDAppDisconnected
)

type ActivityCenterMembershipStatus int
Expand Down Expand Up @@ -100,8 +102,12 @@ type ActivityCenterNotification struct {
TokenData *ActivityTokenData `json:"tokenData"`
//Used for synchronization. Each update should increment the UpdatedAt.
//The value should represent the time when the update occurred.
UpdatedAt uint64 `json:"updatedAt"`
AlbumMessages []*common.Message `json:"albumMessages"`
UpdatedAt uint64 `json:"updatedAt"`
AlbumMessages []*common.Message `json:"albumMessages"`
WalletProviderSessionTopic string `json:"walletProviderSessionTopic"`
yqrashawn marked this conversation as resolved.
Show resolved Hide resolved
DAppURL string `json:"dappURL,omitempty"`
DAppName string `json:"dappName,omitempty"`
DAppIconURL string `json:"dappIconURL,omitempty"`
}

func (n *ActivityCenterNotification) IncrementUpdatedAt(timesource common.TimeSource) {
Expand Down
42 changes: 39 additions & 3 deletions protocol/activity_center_persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

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)

Expand Down Expand Up @@ -147,10 +147,14 @@ func (db sqlitePersistence) SaveActivityCenterNotification(notification *Activit
accepted,
dismissed,
token_data,
wallet_provider_session_topic,
dapp_url,
dapp_name,
dapp_icon_url,
deleted,
updated_at
updated_at
)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
`,
notification.ID,
notification.Timestamp,
Expand All @@ -166,6 +170,10 @@ func (db sqlitePersistence) SaveActivityCenterNotification(notification *Activit
notification.Accepted,
notification.Dismissed,
encodedTokenData,
notification.WalletProviderSessionTopic,
notification.DAppURL,
notification.DAppName,
notification.DAppIconURL,
notification.Deleted,
notification.UpdatedAt,
)
Expand Down Expand Up @@ -211,6 +219,10 @@ func (db sqlitePersistence) parseRowFromTableActivityCenterNotification(rows *sq
&notification.MembershipStatus,
&notification.ContactVerificationStatus,
&tokenDataBytes,
&notification.WalletProviderSessionTopic,
&notification.DAppURL,
&notification.DAppName,
&notification.DAppIconURL,
&notification.Deleted,
&notification.UpdatedAt,
)
Expand Down Expand Up @@ -288,6 +300,10 @@ func (db sqlitePersistence) unmarshalActivityCenterNotificationRow(row *sql.Row)
&name,
&author,
&tokenDataBytes,
&notification.WalletProviderSessionTopic,
&notification.DAppURL,
&notification.DAppName,
&notification.DAppIconURL,
&notification.UpdatedAt)

if err != nil {
Expand Down Expand Up @@ -377,6 +393,10 @@ func (db sqlitePersistence) unmarshalActivityCenterNotificationRows(rows *sql.Ro
&name,
&author,
&tokenDataBytes,
&notification.WalletProviderSessionTopic,
&notification.DAppURL,
&notification.DAppName,
&notification.DAppIconURL,
&latestCursor,
&notification.UpdatedAt)
if err != nil {
Expand Down Expand Up @@ -538,6 +558,10 @@ func (db sqlitePersistence) buildActivityCenterQuery(tx *sql.Tx, params activity
c.name,
a.author,
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,
a.updated_at
FROM activity_center_notifications a
Expand Down Expand Up @@ -659,6 +683,10 @@ func (db sqlitePersistence) GetActivityCenterNotificationsByID(ids []types.HexBy
c.name,
a.author,
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,
a.updated_at
FROM activity_center_notifications a
Expand Down Expand Up @@ -700,6 +728,10 @@ func (db sqlitePersistence) GetActivityCenterNotificationByID(id types.HexBytes)
c.name,
a.author,
a.token_data,
a.wallet_provider_session_topic,
a.dapp_url,
a.dapp_name,
a.dapp_icon_url,
a.updated_at
FROM activity_center_notifications a
LEFT JOIN chats c
Expand Down Expand Up @@ -1334,6 +1366,10 @@ func (db sqlitePersistence) ActiveContactRequestNotification(contactID string) (
c.name,
a.author,
a.token_data,
a.wallet_provider_session_topic,
a.dapp_url,
a.dapp_name,
a.dapp_icon_url,
a.updated_at
FROM activity_center_notifications a
LEFT JOIN chats c ON c.id = a.chat_id
Expand Down
29 changes: 29 additions & 0 deletions protocol/messenger_walletconnect.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package protocol

import (
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/protocol/requests"
"github.com/status-im/status-go/services/wallet/walletconnect"
)

type WalletConnectSession struct {
Expand Down Expand Up @@ -30,6 +32,33 @@ func (m *Messenger) AddWalletConnectSession(request *requests.AddWalletConnectSe
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]
}

response := &MessengerResponse{}
err := m.addActivityCenterNotification(response, notification, nil)

if m.config.messengerSignalsHandler != nil {
m.config.messengerSignalsHandler.MessengerResponse(response)
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To notify client here, you'd do something like this:

if m.config.messengerSignalsHandler != nil {
    response := &MessengerResponse{}
    response.AddActivityCenterNotification(notification)
    m.config.messengerSignalsHandler.MessengerResponse(response)
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though combine it with my next comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, i added and now works fine.

return err
}

func (m *Messenger) GetWalletConnectSession() ([]WalletConnectSession, error) {

return m.getWalletConnectSession()
Expand Down
Loading