Skip to content
This repository was archived by the owner on Jul 29, 2020. It is now read-only.

Commit b2fec1d

Browse files
author
Paul Le Cam
authored
Merge pull request #496 from MainframeHQ/contact-badge
Contact requests badge in side menu
2 parents 267ba34 + d0dcc1a commit b2fec1d

18 files changed

+478
-198
lines changed

package.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"name": "mainframe-os",
3+
"author": "Mainframe Group, Inc",
4+
"description": "A platform for decentralized apps",
35
"version": "0.3.1",
46
"main": "src/main/index.js",
57
"respository": "github:MainframeHQ/mainframe-os",
@@ -40,17 +42,17 @@
4042
}
4143
},
4244
"resolutions": {
43-
"leveldown": "^5.1.1"
45+
"leveldown": "^5.2.0"
4446
},
4547
"dependencies": {
4648
"@babel/polyfill": "^7.6.0",
4749
"@erebos/api-bzz-node": "^0.9.0",
4850
"@erebos/keccak256": "^0.9.0",
4951
"@erebos/secp256k1": "^0.9.0",
5052
"@erebos/timeline": "^0.9.0",
51-
"@ledgerhq/hw-app-eth": "^4.69.2",
52-
"@ledgerhq/hw-transport-node-hid": "^4.68.4",
53-
"@mainframe/eth": "^0.4.0",
53+
"@ledgerhq/hw-app-eth": "^4.70.0",
54+
"@ledgerhq/hw-transport-node-hid": "^4.70.0",
55+
"@mainframe/eth": "^0.4.1",
5456
"@mainframe/rpc-electron": "^0.2.0",
5557
"@mainframe/rpc-handler": "^0.3.0",
5658
"@mainframe/utils-crypto": "^0.4.0",
@@ -59,13 +61,13 @@
5961
"@morpheus-ui/icons": "0.0.16",
6062
"ajv": "^6.10.2",
6163
"bip39": "^3.0.2",
62-
"conf": "^6.0.0",
64+
"conf": "^6.0.1",
6365
"electron-store": "^5.0.0",
6466
"electron-updater": "^4.1.2",
6567
"electron-util": "^0.12.1",
6668
"env-paths": "^2.2.0",
6769
"eth-sig-util": "^2.4.4",
68-
"ethereumjs-tx": "^2.1.1",
70+
"ethereumjs-tx": "1.3.7",
6971
"ethereumjs-util": "^6.1.0",
7072
"ethereumjs-wallet": "^0.6.3",
7173
"ethers": "^4.0.37",
@@ -78,7 +80,7 @@
7880
"keytar": "^4.9.0",
7981
"leveldown": "^5.2.0",
8082
"mime": "^2.4.4",
81-
"nanoid": "^2.1.0",
83+
"nanoid": "^2.1.1",
8284
"object-hash": "^1.3.1",
8385
"pouchdb-adapter-leveldb": "^7.1.1",
8486
"qrcode.react": "^0.9.3",
@@ -119,7 +121,7 @@
119121
"cross-env": "^5.2.1",
120122
"css-loader": "^3.2.0",
121123
"del-cli": "^3.0.0",
122-
"electron": "^6.0.7",
124+
"electron": "^6.0.8",
123125
"electron-builder": "^21.2.0",
124126
"electron-webpack": "^2.7.4",
125127
"eslint": "^6.3.0",

src/main/blockchain/InvitesHandler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export default class InvitesHandler {
133133
this.logger.log({
134134
level: 'debug',
135135
message: 'Fetched invite events',
136-
events: events.toString(),
136+
events,
137137
})
138138

139139
for (let i = 0; i < events.length; i++) {

src/main/context/launcher.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ export class LauncherContext {
189189
}
190190

191191
async subscribe(query: string, variables?: Object = {}): Promise<string> {
192-
// TODO: better check for the subscribe() return, it could be an ExecutionResult with errors
193192
// $FlowFixMe: AsyncIterator
194193
const iterator = await subscribe(
195194
schema,
@@ -199,14 +198,23 @@ export class LauncherContext {
199198
variables,
200199
)
201200

201+
if (iterator.errors && iterator.errors.length > 0) {
202+
this.logger.log({
203+
level: 'error',
204+
message: 'GraphQL subscription failed to create iterator',
205+
errors: iterator.errors.map(e => e.toString()),
206+
})
207+
throw new Error('Failed to create subscription iterator')
208+
}
209+
202210
const subscription = new GraphQLSubscription(iterator)
203211
this._graphqlSubscriptions[subscription.id] = subscription
204212

205-
subscription.start(this.graphqlNotify).catch(error => {
213+
subscription.start(this.graphqlNotify).catch(err => {
206214
this.logger.log({
207215
level: 'error',
208216
message: 'GraphQL subscription notification failed',
209-
error,
217+
error: err.toString(),
210218
})
211219
delete this._graphqlSubscriptions[subscription.id]
212220
})

src/main/db/collections/contacts.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -200,19 +200,16 @@ export default async (
200200
getFirstContactFeed(userAddress, peerAddress),
201201
)
202202

203-
const payload = await encode(
204-
sharedKey,
205-
writeFirstContact({
206-
contact: {
207-
signature,
208-
publicKey: this.keyPair.publicKey,
209-
},
210-
peer: {
211-
publicFeed: userAddress,
212-
},
213-
}),
214-
)
215-
203+
const firstContactData = await writeFirstContact({
204+
contact: {
205+
signature,
206+
publicKey: this.keyPair.publicKey,
207+
},
208+
peer: {
209+
publicFeed: userAddress,
210+
},
211+
})
212+
const payload = await encode(sharedKey, firstContactData)
216213
await feed.publishJSON(user.getBzz(), payload)
217214

218215
logger.log({

src/main/graphql/objects.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,7 @@ export const lookup = new GraphQLObjectType({
950950

951951
export const lookupField = {
952952
type: new GraphQLNonNull(lookup),
953+
resolve: () => ({}),
953954
}
954955

955956
export const systemUpdateStatus = new GraphQLEnumType({

src/main/graphql/subscription.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,15 @@ const contactChanged = {
125125
},
126126
}
127127

128+
const contactsChangedPayload = new GraphQLObjectType({
129+
name: 'contactsChangedPayload',
130+
fields: () => ({
131+
viewer: viewerField,
132+
}),
133+
})
134+
128135
const contactsChanged = {
129-
type: new GraphQLNonNull(contactChangedPayload),
136+
type: new GraphQLNonNull(contactsChangedPayload),
130137
subscribe: async (self, args, ctx: GraphQLContext) => {
131138
const user = await ctx.getUser()
132139
const observable = user.get$('contacts').pipe(
@@ -140,6 +147,28 @@ const contactsChanged = {
140147
},
141148
}
142149

150+
const contactRequestsChangedPayload = new GraphQLObjectType({
151+
name: 'ContactRequestsChangedPayload',
152+
fields: () => ({
153+
viewer: viewerField,
154+
}),
155+
})
156+
157+
const contactRequestsChanged = {
158+
type: new GraphQLNonNull(contactRequestsChangedPayload),
159+
subscribe: async (self, args, ctx: GraphQLContext) => {
160+
const user = await ctx.getUser()
161+
const observable = user.get$('contactRequests').pipe(
162+
map(() => ({
163+
contactRequestsChanged: {
164+
viewer: {},
165+
},
166+
})),
167+
)
168+
return observableToAsyncIterator(observable)
169+
},
170+
}
171+
143172
const systemUpdateChangedPayload = new GraphQLObjectType({
144173
name: 'SystemUpdateChangedPayload',
145174
fields: () => ({
@@ -170,6 +199,7 @@ export default new GraphQLObjectType({
170199
appVersionChanged,
171200
contactChanged,
172201
contactsChanged,
202+
contactRequestsChanged,
173203
systemUpdateChanged,
174204
}),
175205
})

src/renderer/launcher/CopyableBlock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const TextContainer = styled.View`
2222
`
2323

2424
const ButtonContainer = styled.View`
25-
padding: 20px;
25+
padding: 10px;
2626
`
2727

2828
type Props = {

src/renderer/launcher/HomeRouter.js

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import DevtoolsRouter from './devtools/DevtoolsRouter'
1515
import SettingsRouter from './settings/SettingsRouter'
1616
import WalletsScreen from './wallets/WalletsScreen'
1717
import type { HomeRouterAppUpdatesChangedSubscriptionResponse as AppUpdatesData } from './__generated__/HomeRouterAppUpdatesChangedSubscription.graphql'
18+
import type { HomeRouterContactRequestsChangedSubscriptionResponse as ContactRequestsData } from './__generated__/HomeRouterContactRequestsChangedSubscription.graphql'
1819
import type { HomeRouterSystemUpdateChangedSubscriptionResponse as SystemUpdateData } from './__generated__/HomeRouterSystemUpdateChangedSubscription.graphql'
1920

2021
const APP_UPDATES_CHANGED_SUBSCRIPTION = graphql`
@@ -25,36 +26,12 @@ const APP_UPDATES_CHANGED_SUBSCRIPTION = graphql`
2526
}
2627
`
2728

28-
const APP_VERSION_CHANGED_SUBSCRIPTION = graphql`
29-
subscription HomeRouterAppVersionChangedSubscription {
30-
appVersionChanged {
31-
appVersion {
32-
...AppItem_appVersion
33-
}
34-
}
35-
}
36-
`
37-
38-
const CONTACT_CHANGED_SUBSCRIPTION = graphql`
39-
subscription HomeRouterContactChangedSubscription {
40-
contactChanged {
41-
contact {
42-
localID
43-
peerID
44-
publicID
45-
connectionState
46-
invite {
47-
...InviteContactModal_contactInvite
48-
ethNetwork
49-
fromAddress
50-
inviteTX
51-
stakeState
52-
stakeAmount
53-
reclaimedStakeTX
54-
}
55-
profile {
56-
name
57-
ethAddress
29+
const CONTACT_REQUESTS_CHANGED_SUBSCRIPTION = graphql`
30+
subscription HomeRouterContactRequestsChangedSubscription {
31+
contactRequestsChanged {
32+
viewer {
33+
contactRequests {
34+
localID
5835
}
5936
}
6037
}
@@ -94,8 +71,13 @@ export default function HomeRouter() {
9471
useSubscription(APP_UPDATES_CHANGED_SUBSCRIPTION, (data: AppUpdatesData) => {
9572
setBadges(b => ({ ...b, apps: data.appUpdatesChanged.appUpdatesCount > 0 }))
9673
})
97-
useSubscription(APP_VERSION_CHANGED_SUBSCRIPTION)
98-
useSubscription(CONTACT_CHANGED_SUBSCRIPTION)
74+
useSubscription(
75+
CONTACT_REQUESTS_CHANGED_SUBSCRIPTION,
76+
(data: ContactRequestsData) => {
77+
const { contactRequests } = data.contactRequestsChanged.viewer
78+
setBadges(b => ({ ...b, contacts: contactRequests.length > 0 }))
79+
},
80+
)
9981
useSubscription(
10082
SYSTEM_UPDATE_CHANGED_SUBSCRIPTION,
10183
(data: SystemUpdateData) => {

0 commit comments

Comments
 (0)