Skip to content

Commit fc146fe

Browse files
authored
Move payment request notifications to Cloud Function (#430)
### Description Moved the payment requests notification sending from the notification service to a database-triggered Cloud Function. See https://www.notion.so/clabsco/Notification-Service-Indexer-064ca4f58be64c3384ac8fb5f00fca56 for more information on the motivation for doing this. ### Other changes N/A ### Tested Manually and added unit test. This is deployed in Alfajores. ### How others should test Send a payment request to an address. See that the requested address receives a push notification. ### Related issues - Fixes #428 ### Backwards compatibility N/A
1 parent 44d6d81 commit fc146fe

File tree

24 files changed

+352
-175
lines changed

24 files changed

+352
-175
lines changed

crowdin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ files:
55
translation: /packages/mobile/ios/celo/%osx_code%/%original_file_name%
66
- source: /packages/notification-service/locales/en.json
77
translation: /packages/notification-service/locales/%two_letters_code%.json
8+
- source: /packages/cloud-functions/locales/en.json
9+
translation: /packages/cloud-functions/locales/%two_letters_code%.json

packages/cloud-functions/.firebaserc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"projects": {
33
"alfajores": "celo-mobile-alfajores",
44
"mainnet": "celo-mobile-mainnet",
5-
"testnet": "celo-testnet-production"
5+
"testnet": "celo-testnet-production",
6+
"default": "celo-mobile-alfajores"
67
}
78
}

packages/cloud-functions/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ dist/
22

33
# Firebase cache
44
.firebase/
5+
.runtimeconfig.json
6+
database-debug.log
7+
ui-debug.log
58

69
# Only check in encrypted .env file
710
.env
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
{
22
"functions": {
33
"source": ".",
4-
"predeploy": ["yarn run lint", "yarn run build"]
4+
"predeploy": [
5+
"yarn run lint",
6+
"yarn run build"
7+
]
8+
},
9+
"emulators": {
10+
"functions": {
11+
"port": 5001
12+
},
13+
"database": {
14+
"port": 9000
15+
},
16+
"ui": {
17+
"enabled": true
18+
}
519
}
620
}

packages/cloud-functions/jest_setup.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ jest.mock('firebase-functions', () => ({
66
https: {
77
onRequest: jest.fn,
88
},
9+
database: {
10+
ref: () => ({
11+
onWrite: jest.fn,
12+
}),
13+
},
914
pubsub: {
1015
schedule: () => ({
1116
onRun: jest.fn,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"paymentRequestedTitle": "Payment Requested",
3+
"paymentRequestedBody": "Payment of {{amount}} {{currency}} has been requested"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"paymentRequestedTitle": "Pago solicitado",
3+
"paymentRequestedBody": "Se ha solicitado pago de {{amount}} {{currency}}."
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"paymentRequestedTitle": "Pagamento solicitado",
3+
"paymentRequestedBody": "Foi solicitado um pagamento de {{amount}} {{currency}}."
4+
}

packages/cloud-functions/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,26 @@
1818
},
1919
"dependencies": {
2020
"@celo/contractkit": "1.2.2-beta",
21-
"@celo/eslint-config-typescript": "0.0.1",
2221
"@celo/utils": "1.2.2-beta",
2322
"@google-cloud/bigquery": "~5.5.0",
24-
"@typescript-eslint/eslint-plugin": "^4.25.0",
25-
"eslint": "^7.27.0",
26-
"eslint-plugin-import": "^2.23.3",
27-
"eslint-plugin-react": "^7.23.2",
28-
"eslint-plugin-react-hooks": "^4.2.0",
29-
"eslint-plugin-react-native": "^3.11.0",
3023
"bignumber.js": "^9.0.0",
3124
"fast-json-stable-stringify": "~2.1.0",
3225
"firebase-admin": "^9.5.0",
3326
"firebase-functions": "^3.6.0",
27+
"i18next": "~19.0.2",
3428
"jsonwebtoken": "~8.5.1",
35-
"prom-client": "^13.1.0",
3629
"uuid": "^8.3.0"
3730
},
3831
"devDependencies": {
32+
"@celo/eslint-config-typescript": "0.0.1",
3933
"@types/jsonwebtoken": "~8.5.0",
4034
"@types/uuid": "^8.3.0",
35+
"@typescript-eslint/eslint-plugin": "^4.25.0",
36+
"eslint": "^7.27.0",
37+
"eslint-plugin-import": "^2.23.3",
38+
"eslint-plugin-react": "^7.23.2",
39+
"eslint-plugin-react-hooks": "^4.2.0",
40+
"eslint-plugin-react-native": "^3.11.0",
4141
"firebase-functions-test": "^0.2.0",
4242
"jest-fetch-mock": "^3.0.3"
4343
},

packages/cloud-functions/src/config.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const functions = require('firebase-functions')
1+
import * as functions from 'firebase-functions'
2+
import i18next from 'i18next'
3+
24
// This allows us to access Cloud Function environment variables
35
const config = functions.config()
46

@@ -78,3 +80,28 @@ export enum DigitalAsset {
7880
}
7981

8082
export const FETCH_TIMEOUT_DURATION = 10000 // 10 seconds
83+
export const NOTIFICATIONS_TTL_MS = 3600 * 1000 * 24 * 7 // 1 week in milliseconds
84+
85+
const en = require('../locales/en.json')
86+
const es = require('../locales/es.json')
87+
const pt = require('../locales/pt.json')
88+
89+
i18next
90+
.init({
91+
lng: 'en',
92+
resources: {
93+
en: {
94+
translation: en,
95+
},
96+
es: {
97+
translation: es,
98+
},
99+
pt: {
100+
translation: pt,
101+
},
102+
},
103+
fallbackLng: {
104+
default: ['en'],
105+
},
106+
})
107+
.catch((reason: any) => console.error('Config', 'Failed to init i18n', reason))

0 commit comments

Comments
 (0)