alpha-wallet-android icon indicating copy to clipboard operation
alpha-wallet-android copied to clipboard

Implement push notification

Open hboon opened this issue 2 years ago • 10 comments

Summary: upon silent/data push, fetch transaction history in the background and if we can find the transaction (why not?), show the user a notification


  • AlphaWallet apps calls and the server endpoint to register a wallet 0xb0b
  • Server monitors 0xb0b for change of receive of native crypto, ERC-20, ERC-721, ERC-1155
  • Server sends a silent push to all AlphaWallet apps device tokens that registered for 0xb0b
  • Upon receive a silent push for 0xb0b, AlphaWallet apps fetches/refreshes transaction history for 0xb0b in the background
  • AlphaWallet displays a notification that "0xb0b has received X ETH" or "0xb0b has received Some App 123"
  • User tap the notification to see that transaction/activity
  1. Verify we get notifications for receiving of native crypto, ERC-20, ERC-721, ERC-1155 (did I miss anything?) on Ethereum mainnet.
  2. iOS test getting pushes too like Android did
  3. We build it in AlphaWallet and try it for a few hardcoded wallets that we own. Ship it
  4. Extend it to more people or everyone (depending on confidence level and how much work to rollout) and ship it.

Makes sense? Did I miss anything? So I think you can proceed with (1) and (3) and on iOS side, we'll do (1) and (2).

Just to be safe, remember gate it with a feature flag in case it isn't ready.

hboon avatar Mar 27 '23 00:03 hboon

Just to add more information -

There are two things needed to start receiving data messages:

  1. Call the server endpoint via POST /subscriptions
  2. Subscribe to topic via Firebase. The string format is {wallet}-{chainId} e.g 0xb0b-1

This is a sample data message:

{
  "body": {
    "to": "0x11b815efB8f581194ae79006d24E0d814B7697F6",
    "from": "0x96974F62Ce2a72959e9B1A682886D70E20B51A0c",
    "chain": 1,
    "event": "transfer",
    "contract": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
    "blockNumber": 16879409,
    "contractType": "erc20"
  },
  "title": {
    "contract": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
    "wallet": "0x11b815efB8f581194ae79006d24E0d814B7697F6",
    "createdAt": "1679442974168",
    "chainId": "1",
    "event": "transfer"
  }
}

justindg avatar Mar 27 '23 02:03 justindg

If it's a swap from X to Y token. What notifications do we get?

hboon avatar Mar 27 '23 02:03 hboon

  • AlphaWallet apps calls and the server endpoint to register a wallet 0xb0b

do we send request to this endpoint only when we create a new wallet, and when register already created wallet. do we need to handle on client wether we've registered wallet or we able to make multiple calls? or response of POST /subscriptions would return subscriptions mapped to wallet address, and chain id?

oa-s avatar Apr 19 '23 10:04 oa-s

do we need to handle server changing here enable/disable with calling appropriate method subscribe/unsubscribe for each subscribed wallet?

oa-s avatar Apr 19 '23 10:04 oa-s

AlphaWallet apps calls and the server endpoint to register a wallet 0xb0b

do we send request to this endpoint only when we create a new wallet, and when register already created wallet. do we need to handle on client wether we've registered wallet or we able to make multiple calls? or response of POST /subscriptions would return subscriptions mapped to wallet address, and chain id?

Make the registration calls as soon as (or delay if there's a good reason) we know the user creates or imports a wallet. This is for the server to start fetching and tracking transactions for that wallet. BTW, only Ethereum mainnet is supported at the moment, but I think we don't have to specifically handle that in the app.

do we need to handle on client wether we've registered wallet or we able to make multiple calls?

If this is to handle the case where we tried to register but failed or didn't make the call, then yes, we should be able to handle that. The servers should handle multiple invocations. So I guess we can check after making the register call and if it's successful, set a flag. Subsequently only call if that local flag is false?

hboon avatar Apr 20 '23 01:04 hboon

do we need to handle server changing here enable/disable with calling appropriate method subscribe/unsubscribe for each subscribed wallet?

Server as in user changing which changes are enabled? — Then, no.

I don't think there's an unsubscribe function, yet :P

hboon avatar Apr 20 '23 01:04 hboon

do we need to handle server changing here enable/disable with calling appropriate method subscribe/unsubscribe for each subscribed wallet?

Server as in user changing which changes are enabled? — Then, no.

I don't think there's an unsubscribe function, yet :P

Unsubscribe function is available too :)

justindg avatar Apr 20 '23 01:04 justindg

Haha. When do you call it?

hboon avatar Apr 20 '23 02:04 hboon

Haha. When do you call it?

For now, when wallet is deleted

justindg avatar Apr 20 '23 02:04 justindg

@justindg could u please share a base url for subscriptions, in case u have it, and wallet address for testing, in dm please.

oa-s avatar Apr 20 '23 08:04 oa-s