Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit d15dbc2

Browse files
Referral code refactor/fixes (#4277)
* display message when there is no active campaign * prettier * bug fix * disable the autopass * translate the conrtents * re-set the autopass * handle when there is no active growth campaign * improve link * correct the attestation account id * separate growth referral code creation logic into a separate package * fix referral creation on notifications side * prettify * fix lint problem * prettify * prettify * undo mistake * fix typo * undoing change * move utils functionality to growth-shared * remove desktop invite code length restriction * minor fixes Co-authored-by: Shahul Hameed <[email protected]>
1 parent 1dfca9a commit d15dbc2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+129
-106
lines changed

.circleci/config.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ jobs:
133133
at: .
134134
- run: cd packages/auth-utils && yarn migrate
135135
- run: cd infra/identity && yarn migrate
136-
- run: cd infra/growth-event && yarn migrate
136+
- run: cd infra/growth-shared && yarn migrate
137137
- run:
138138
name: Run Bridge Tests
139139
command: cd infra/bridge && yarn migrate && yarn test
@@ -164,7 +164,7 @@ jobs:
164164
- run: cd infra/bridge && yarn migrate
165165
- run: cd infra/discovery && yarn migrate
166166
- run: cd infra/growth && yarn migrate
167-
- run: cd infra/growth-event && yarn migrate
167+
- run: cd infra/growth-shared && yarn migrate
168168
- run: cd infra/identity && yarn migrate
169169
- run:
170170
name: Run Discovery Tests
@@ -176,7 +176,7 @@ jobs:
176176
- attach_workspace:
177177
at: .
178178
- run: cd infra/growth && yarn migrate
179-
- run: cd infra/growth-event && yarn migrate
179+
- run: cd infra/growth-shared && yarn migrate
180180
- run: cd infra/identity && yarn migrate
181181
- run: cd infra/discovery && yarn migrate
182182
- run:
@@ -189,7 +189,7 @@ jobs:
189189
- attach_workspace:
190190
at: .
191191
- run: cd infra/growth && yarn migrate
192-
- run: cd infra/growth-event && yarn migrate
192+
- run: cd infra/growth-shared && yarn migrate
193193
- run: cd infra/identity && yarn migrate
194194
- run: cd packages/auth-utils && yarn migrate
195195
- run:

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ COPY ./infra/notifications/package.json ./infra/notifications/
3030
COPY ./infra/growth/package.json ./infra/growth/
3131
COPY ./infra/identity/package.json ./infra/identity/
3232
COPY ./infra/bridge/package.json ./infra/bridge/
33-
COPY ./infra/growth-event/package.json ./infra/growth-event/
33+
COPY ./infra/growth-shared/package.json ./infra/growth-shared/
3434
COPY ./infra/auth-server/package.json ./infra/auth-server/
3535
COPY ./packages/auth-utils/package.json ./packages/auth-utils/
3636

dapps/marketplace/src/pages/growth/Welcome.js

-7
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ class GrowthWelcome extends Component {
3636
// code so ignore it.
3737
inviteCode = inviteCode !== 'onboard' ? inviteCode : undefined
3838

39-
if (inviteCode && inviteCode.length !== 11) {
40-
console.warn(
41-
`Unexpected invite code ${inviteCode}. Invite code should be 11 characters long.`
42-
)
43-
inviteCode = undefined
44-
}
45-
4639
const localStorageKey = 'growth_invite_code'
4740

4841
const storedInviteCode = localStorage.getItem(localStorageKey)

devops/dockerfiles/event-listener

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ COPY ./packages/services ./packages/services
2828
COPY ./packages/validator ./packages/validator
2929
COPY ./packages/token ./packages/token
3030
COPY ./infra/discovery ./infra/discovery
31-
COPY ./infra/growth-event ./infra/growth-event
31+
COPY ./infra/growth-shared ./infra/growth-shared
3232
COPY ./infra/identity ./infra/identity
3333
COPY ./packages/auth-utils ./packages/auth-utils
3434
COPY ./packages/auth-client ./packages/auth-client

devops/dockerfiles/origin-bridge

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ COPY ./packages/ip2geo ./packages/ip2geo
1919
COPY ./packages/validator ./packages/validator
2020
COPY ./infra/bridge ./infra/bridge
2121
COPY ./infra/identity ./infra/identity
22-
COPY ./infra/growth-event ./infra/growth-event
22+
COPY ./infra/growth-shared ./infra/growth-shared
2323
COPY ./packages/auth-utils ./packages/auth-utils
2424

2525
RUN yarn install

devops/dockerfiles/origin-cron

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ COPY ./packages/validator ./packages/validator
2828
COPY ./packages/contracts ./packages/contracts
2929
COPY ./packages/token ./packages/token
3030
COPY ./infra/consistency ./infra/consistency
31-
COPY ./infra/growth-event ./infra/growth-event
31+
COPY ./infra/growth-shared ./infra/growth-shared
3232
COPY ./infra/cron ./infra/cron
3333
COPY ./infra/discovery ./infra/discovery
3434
COPY ./infra/growth ./infra/growth

devops/dockerfiles/origin-discovery

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ COPY ./packages/services ./packages/services
2222
COPY ./packages/validator ./packages/validator
2323
COPY ./packages/token ./packages/token
2424
COPY ./infra/discovery ./infra/discovery
25-
COPY ./infra/growth-event ./infra/growth-event
25+
COPY ./infra/growth-shared ./infra/growth-shared
2626
COPY ./infra/identity ./infra/identity
2727

2828
RUN yarn install

devops/dockerfiles/origin-faucet

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ COPY ./packages/contracts ./packages/contracts
1717
COPY ./packages/token ./packages/token
1818
COPY ./packages/ipfs ./packages/ipfs
1919
COPY ./infra/identity ./infra/identity
20-
COPY ./infra/growth-event ./infra/growth-event
20+
COPY ./infra/growth-shared ./infra/growth-shared
2121
COPY ./infra/faucet ./infra/faucet
2222

2323
RUN yarn install

devops/dockerfiles/origin-notifications

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ COPY ./packages/validator ./packages/validator
2727
COPY ./packages/contracts ./packages/contracts
2828
COPY ./packages/token ./packages/token
2929
COPY ./infra/discovery ./infra/discovery
30-
COPY ./infra/growth-event ./infra/growth-event
30+
COPY ./infra/growth-shared ./infra/growth-shared
3131
# @origin/identity required for the db model
3232
COPY ./infra/identity ./infra/identity
3333
COPY ./packages/auth-utils ./packages/auth-utils

devops/dockerfiles/origin-growth renamed to devops/dockerfiles/origin-shared

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ COPY ./packages/contracts ./packages/contracts
2929
COPY ./packages/token ./packages/token
3030
COPY ./infra/discovery ./infra/discovery
3131
COPY ./infra/growth ./infra/growth
32-
COPY ./infra/growth-event ./infra/growth-event
32+
COPY ./infra/growth-shared ./infra/growth-shared
3333
COPY ./infra/identity ./infra/identity
3434

3535
RUN yarn install
3636

3737
# Run migrations then start the growth server.
3838
CMD eval "$(envkey-source)" && \
3939
npm run migrate --prefix infra/growth && \
40-
npm run migrate --prefix infra/growth-event && \
40+
npm run migrate --prefix infra/growth-shared && \
4141
npm run start --prefix infra/growth

docker-compose.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,15 @@ services:
5959
- ./packages/validator:/app/packages/validator/
6060
- ./packages/token/:/app/packages/token/
6161
- ./packages/auth-client/:/app/packages/auth-client/
62+
- ./packages/utils/:/app/packages/utils/
6263
# Infrastructure packages
6364
- ./infra/bridge/:/app/infra/bridge/
6465
- ./infra/discovery/:/app/infra/discovery/
6566
- ./infra/ipfs-proxy/:/app/infra/ipfs-proxy/
6667
- ./infra/messaging/:/app/infra/messaging/
6768
- ./infra/notifications/:/app/infra/notifications/
6869
- ./infra/growth/:/app/infra/growth/
69-
- ./infra/growth-event/:/app/infra/growth-event/
70+
- ./infra/growth-shared/:/app/infra/growth-shared/
7071
- ./infra/identity/:/app/infra/identity/
7172
- ./infra/auth-server/:/app/infra/auth-server/
7273
- ./packages/auth-utils/:/app/packages/auth-utils/
@@ -90,7 +91,7 @@ services:
9091
- /app/infra/messaging/node_modules/
9192
- /app/infra/notifications/node_modules/
9293
- /app/infra/growth/node_modules/
93-
- /app/infra/growth-event/node_modules/
94+
- /app/infra/growth-shared/node_modules/
9495
- /app/infra/identity/node_modules/
9596
- /app/infra/auth-server/node_modules/
9697
- /app/packages/auth-utils/node_modules/
@@ -110,7 +111,7 @@ services:
110111
>
111112
/bin/bash -c "npm run migrate --prefix infra/discovery &&
112113
npm run migrate --prefix infra/growth &&
113-
npm run migrate --prefix infra/growth-event &&
114+
npm run migrate --prefix infra/growth-shared &&
114115
npm run migrate --prefix infra/identity &&
115116
npm run migrate --prefix infra/notifications &&
116117
npm run migrate --prefix infra/bridge &&

infra/bridge/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"dependencies": {
3232
"@google-cloud/pubsub": "1.3.0",
3333
"@origin/auth-utils": "^0.1.0",
34-
"@origin/growth-event": "^0.1.0",
34+
"@origin/growth-shared": "^0.1.0",
3535
"@origin/identity": "^0.1.0",
3636
"@origin/ip2geo": "^0.1.0",
3737
"@sendgrid/mail": "^6.4.0",

infra/bridge/src/controllers/identity.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const get = require('lodash/get')
66
const router = express.Router()
77

88
const authMiddleware = require('@origin/auth-utils/src/middleware/auth')
9-
const { GrowthEvent } = require('@origin/growth-event/src/resources/event')
9+
const { GrowthEvent } = require('@origin/growth-shared/src/resources/event')
1010
const {
1111
loadAttestationMetadata,
1212
loadIdentityAddresses,

infra/bridge/src/controllers/promotions.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
const express = require('express')
44
const router = express.Router()
55

6-
const { GrowthEvent } = require('@origin/growth-event/src/resources/event')
6+
const { GrowthEvent } = require('@origin/growth-shared/src/resources/event')
77
const {
88
GrowthEventTypes,
99
GrowthEventStatuses
10-
} = require('@origin/growth-event/src/enums')
10+
} = require('@origin/growth-shared/src/enums')
1111

1212
const {
1313
hashContent,

infra/bridge/src/utils/growth-event-helpers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
const logger = require('../logger')
44

5-
const { GrowthEvent } = require('@origin/growth-event/src/resources/event')
6-
const { GrowthEventTypes } = require('@origin/growth-event/src/enums')
5+
const { GrowthEvent } = require('@origin/growth-shared/src/resources/event')
6+
const { GrowthEventTypes } = require('@origin/growth-shared/src/enums')
77

88
const db = require('@origin/identity/src/models')
99

infra/discovery/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"dependencies": {
1818
"@google-cloud/pubsub": "1.3.0",
1919
"@origin/graphql": "^0.1.1",
20-
"@origin/growth-event": "^0.1.0",
20+
"@origin/growth-shared": "^0.1.0",
2121
"@origin/identity": "^0.1.0",
2222
"@origin/ipfs": "^0.1.0",
2323
"@origin/ip2geo": "^0.1.0",

infra/discovery/src/listener/handler_identity.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const get = require('lodash/get')
22
const Web3 = require('web3')
33

44
const originIpfs = require('@origin/ipfs')
5-
const { GrowthEvent } = require('@origin/growth-event/src/resources/event')
5+
const { GrowthEvent } = require('@origin/growth-shared/src/resources/event')
66
const {
77
convertLegacyAvatar,
88
loadAttestationMetadata,

infra/discovery/src/listener/handler_marketplace.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ const esmImport = require('esm')(module)
22
const logger = require('./logger')
33
const search = require('../lib/search')
44
const db = require('../models')
5-
const { GrowthEvent } = require('@origin/growth-event/src/resources/event')
6-
const { GrowthEventTypes } = require('@origin/growth-event/src/enums')
5+
const { GrowthEvent } = require('@origin/growth-shared/src/resources/event')
6+
const { GrowthEventTypes } = require('@origin/growth-shared/src/enums')
77
const listingQuery = require('./queries/Listing')
88
const offerQuery = require('./queries/Offer')
99
const { getOriginListingId, getOriginOfferId } = esmImport(

infra/discovery/test/listener-handler.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const sinon = require('sinon')
33
const expect = chai.expect
44
const esmImport = require('esm')(module)
55

6-
const { GrowthEvent } = require('@origin/growth-event/src/resources/event')
7-
const { GrowthEventTypes } = require('@origin/growth-event/src/enums')
6+
const { GrowthEvent } = require('@origin/growth-shared/src/resources/event')
7+
const { GrowthEventTypes } = require('@origin/growth-shared/src/enums')
88

99
const graphqlClient = esmImport('@origin/graphql').default
1010

infra/growth-event/README.md

-2
This file was deleted.
File renamed without changes.
File renamed without changes.

infra/growth-shared/README.md

+2
File renamed without changes.

infra/growth-event/package.json renamed to infra/growth-shared/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "@origin/growth-event",
3-
"description": "Growth event migration files, models and resources",
2+
"name": "@origin/growth-shared",
3+
"description": "Shared growth functionality: growth event migration files, models and resources",
44
"version": "0.1.0",
55
"engines": {
66
"node": "10.x"
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const {
2+
GrowthReferral,
3+
GrowthInviteCode
4+
} = require('@origin/growth-shared/src/models')
5+
6+
async function _getReferrer(code) {
7+
// Lookup the code.
8+
const inviteCode = await GrowthInviteCode.findOne({ where: { code } })
9+
if (!inviteCode) {
10+
throw new Error(`Invalid invite code ${code}`)
11+
}
12+
return inviteCode.ethAddress
13+
}
14+
15+
async function makeReferralConnection(code, walletAddress) {
16+
walletAddress = walletAddress.toLowerCase()
17+
const referralLink = await GrowthReferral.findOne({
18+
where: {
19+
refereeEthAddress: walletAddress
20+
}
21+
})
22+
const referrer = await _getReferrer(code)
23+
24+
if (referrer === walletAddress) {
25+
throw new Error(`Referrer ${referrer} can't use own referral code`)
26+
}
27+
28+
const returnObj = {
29+
referrer
30+
}
31+
32+
if (referralLink) {
33+
if (referralLink.referrerEthAddress !== referrer) {
34+
/* The referrer associated with the invite code does not match previously stored referrer.
35+
* A corner case scenario this might happen is as follow:
36+
* - referee receives multiple invites.
37+
* - referee clicks on an invite and enrolls into growth campaing
38+
* - referee clicks on another invite link and enrolls again into
39+
* growth campaign.
40+
*
41+
* When this happens we ignore the subsequent invites and attribute all
42+
* referees actions to the initial referrer.
43+
*
44+
*/
45+
throw new Error(
46+
`Referee ${walletAddress} already referred by ${referralLink.referrerEthAddress}`
47+
)
48+
} else {
49+
// the referrer -> referee link already created
50+
return returnObj
51+
}
52+
}
53+
54+
await GrowthReferral.create({
55+
referrerEthAddress: referrer,
56+
refereeEthAddress: walletAddress
57+
})
58+
59+
return returnObj
60+
}
61+
62+
module.exports = {
63+
makeReferralConnection
64+
}

infra/growth/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"@origin/auth-utils": "^0.1.0",
1515
"@origin/discovery": "^0.1.0",
1616
"@origin/graphql": "^0.1.1",
17-
"@origin/growth-event": "^0.1.0",
17+
"@origin/growth-shared": "^0.1.0",
1818
"@origin/identity": "^0.1.0",
1919
"@origin/ip2geo": "^0.1.0",
2020
"@origin/token": "^0.1.0",

infra/growth/src/apollo/resolvers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const { sendInvites, sendInviteReminder } = require('../resources/email')
2020
const enums = require('../enums')
2121
const logger = require('../logger')
2222
const { BannedUserError } = require('../util/bannedUserError')
23-
const { GrowthEvent } = require('@origin/growth-event/src/resources/event')
23+
const { GrowthEvent } = require('@origin/growth-shared/src/resources/event')
2424

2525
const requireEnrolledUser = context => {
2626
if (
@@ -205,7 +205,7 @@ const resolvers = {
205205
if (args.inviteCode) {
206206
await GrowthInvite.makeReferralConnection(
207207
args.inviteCode,
208-
args.accountId
208+
context.walletAddress
209209
)
210210
}
211211

infra/growth/src/enums.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const {
77
Enum,
88
GrowthEventStatuses,
99
GrowthEventTypes
10-
} = require('@origin/growth-event/src/enums')
10+
} = require('@origin/growth-shared/src/enums')
1111

1212
const GrowthCampaignRewardStatuses = new Enum(
1313
'NotReady',

infra/growth/src/models/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const _growthEventModels = require('@origin/growth-event/src/models')
3+
const _growthEventModels = require('@origin/growth-shared/src/models')
44

55
const fs = require('fs')
66
const path = require('path')

0 commit comments

Comments
 (0)