mirror of
https://github.com/status-im/status-go.git
synced 2025-02-18 17:57:28 +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.EnsService().Init(messenger.SyncEnsNamesWithDispatchMessage)
|
||||
b.statusNode.CommunityTokensService().Init(messenger)
|
||||
|
||||
if walletService := b.statusNode.WalletService(); walletService != nil {
|
||||
walletService.InjectMessenger(messenger)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -42,6 +42,8 @@ const (
|
||||
ActivityCenterNotificationTypeCommunityUnbanned
|
||||
ActivityCenterNotificationTypeNewInstallationReceived
|
||||
ActivityCenterNotificationTypeNewInstallationCreated
|
||||
ActivityCenterNotificationTypeDAppConnected
|
||||
ActivityCenterNotificationTypeDAppDisconnected
|
||||
)
|
||||
|
||||
type ActivityCenterMembershipStatus int
|
||||
@ -103,8 +105,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"`
|
||||
DAppURL string `json:"dappURL,omitempty"`
|
||||
DAppName string `json:"dappName,omitempty"`
|
||||
DAppIconURL string `json:"dappIconURL,omitempty"`
|
||||
}
|
||||
|
||||
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,
|
||||
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)
|
||||
|
||||
@ -147,11 +147,15 @@ func (db sqlitePersistence) SaveActivityCenterNotification(notification *Activit
|
||||
accepted,
|
||||
dismissed,
|
||||
token_data,
|
||||
wallet_provider_session_topic,
|
||||
dapp_url,
|
||||
dapp_name,
|
||||
dapp_icon_url,
|
||||
deleted,
|
||||
updated_at,
|
||||
installation_id
|
||||
updated_at,
|
||||
installation_id
|
||||
)
|
||||
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
||||
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
||||
`,
|
||||
notification.ID,
|
||||
notification.Timestamp,
|
||||
@ -167,6 +171,10 @@ func (db sqlitePersistence) SaveActivityCenterNotification(notification *Activit
|
||||
notification.Accepted,
|
||||
notification.Dismissed,
|
||||
encodedTokenData,
|
||||
notification.WalletProviderSessionTopic,
|
||||
notification.DAppURL,
|
||||
notification.DAppName,
|
||||
notification.DAppIconURL,
|
||||
notification.Deleted,
|
||||
notification.UpdatedAt,
|
||||
notification.InstallationID,
|
||||
@ -213,6 +221,10 @@ func (db sqlitePersistence) parseRowFromTableActivityCenterNotification(rows *sq
|
||||
¬ification.MembershipStatus,
|
||||
¬ification.ContactVerificationStatus,
|
||||
&tokenDataBytes,
|
||||
¬ification.WalletProviderSessionTopic,
|
||||
¬ification.DAppURL,
|
||||
¬ification.DAppName,
|
||||
¬ification.DAppIconURL,
|
||||
¬ification.Deleted,
|
||||
¬ification.UpdatedAt,
|
||||
)
|
||||
@ -291,9 +303,12 @@ func (db sqlitePersistence) unmarshalActivityCenterNotificationRow(row *sql.Row)
|
||||
&name,
|
||||
&author,
|
||||
&tokenDataBytes,
|
||||
¬ification.WalletProviderSessionTopic,
|
||||
¬ification.DAppURL,
|
||||
¬ification.DAppName,
|
||||
¬ification.DAppIconURL,
|
||||
¬ification.UpdatedAt,
|
||||
&installationID,
|
||||
)
|
||||
&installationID)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -387,6 +402,10 @@ func (db sqlitePersistence) unmarshalActivityCenterNotificationRows(rows *sql.Ro
|
||||
&name,
|
||||
&author,
|
||||
&tokenDataBytes,
|
||||
¬ification.WalletProviderSessionTopic,
|
||||
¬ification.DAppURL,
|
||||
¬ification.DAppName,
|
||||
¬ification.DAppIconURL,
|
||||
&latestCursor,
|
||||
¬ification.UpdatedAt,
|
||||
&installationID,
|
||||
@ -554,6 +573,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,
|
||||
a.installation_id
|
||||
@ -676,6 +699,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,
|
||||
a.installation_id
|
||||
@ -718,6 +745,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,
|
||||
a.installation_id
|
||||
FROM activity_center_notifications a
|
||||
@ -1353,6 +1384,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,
|
||||
a.installation_id
|
||||
FROM activity_center_notifications a
|
||||
|
@ -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 {
|
||||
@ -30,6 +32,28 @@ 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]
|
||||
}
|
||||
|
||||
_, err := m.persistence.SaveActivityCenterNotification(notification, true)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *Messenger) GetWalletConnectSession() ([]WalletConnectSession, error) {
|
||||
|
||||
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
|
||||
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
|
||||
err := json.Unmarshal([]byte(session_json), &session)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unmarshal session: %v", err)
|
||||
return session, fmt.Errorf("unmarshal session: %v", err)
|
||||
}
|
||||
|
||||
chains := supportedChainsInSession(session)
|
||||
testChains, err := areTestChains(networks, chains)
|
||||
if err != nil {
|
||||
return fmt.Errorf("areTestChains: %v", err)
|
||||
return session, fmt.Errorf("areTestChains: %v", err)
|
||||
}
|
||||
|
||||
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]
|
||||
}
|
||||
|
||||
return UpsertSession(db, rowEntry)
|
||||
return session, UpsertSession(db, rowEntry)
|
||||
}
|
||||
|
||||
// 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},
|
||||
}
|
||||
timestampBeforeAddSession := time.Now().Unix()
|
||||
err := AddSession(db, networks, sessionJSON)
|
||||
_, err := AddSession(db, networks, sessionJSON)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Validate that session was written correctly to the database
|
||||
|
Loading…
x
Reference in New Issue
Block a user