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

Commit

Permalink
Merge pull request #496 from MainframeHQ/contact-badge
Browse files Browse the repository at this point in the history
Contact requests badge in side menu
  • Loading branch information
Paul Le Cam authored Sep 12, 2019
2 parents 267ba34 + d0dcc1a commit b2fec1d
Showing 18 changed files with 478 additions and 198 deletions.
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"name": "mainframe-os",
"author": "Mainframe Group, Inc",
"description": "A platform for decentralized apps",
"version": "0.3.1",
"main": "src/main/index.js",
"respository": "github:MainframeHQ/mainframe-os",
@@ -40,17 +42,17 @@
}
},
"resolutions": {
"leveldown": "^5.1.1"
"leveldown": "^5.2.0"
},
"dependencies": {
"@babel/polyfill": "^7.6.0",
"@erebos/api-bzz-node": "^0.9.0",
"@erebos/keccak256": "^0.9.0",
"@erebos/secp256k1": "^0.9.0",
"@erebos/timeline": "^0.9.0",
"@ledgerhq/hw-app-eth": "^4.69.2",
"@ledgerhq/hw-transport-node-hid": "^4.68.4",
"@mainframe/eth": "^0.4.0",
"@ledgerhq/hw-app-eth": "^4.70.0",
"@ledgerhq/hw-transport-node-hid": "^4.70.0",
"@mainframe/eth": "^0.4.1",
"@mainframe/rpc-electron": "^0.2.0",
"@mainframe/rpc-handler": "^0.3.0",
"@mainframe/utils-crypto": "^0.4.0",
@@ -59,13 +61,13 @@
"@morpheus-ui/icons": "0.0.16",
"ajv": "^6.10.2",
"bip39": "^3.0.2",
"conf": "^6.0.0",
"conf": "^6.0.1",
"electron-store": "^5.0.0",
"electron-updater": "^4.1.2",
"electron-util": "^0.12.1",
"env-paths": "^2.2.0",
"eth-sig-util": "^2.4.4",
"ethereumjs-tx": "^2.1.1",
"ethereumjs-tx": "1.3.7",
"ethereumjs-util": "^6.1.0",
"ethereumjs-wallet": "^0.6.3",
"ethers": "^4.0.37",
@@ -78,7 +80,7 @@
"keytar": "^4.9.0",
"leveldown": "^5.2.0",
"mime": "^2.4.4",
"nanoid": "^2.1.0",
"nanoid": "^2.1.1",
"object-hash": "^1.3.1",
"pouchdb-adapter-leveldb": "^7.1.1",
"qrcode.react": "^0.9.3",
@@ -119,7 +121,7 @@
"cross-env": "^5.2.1",
"css-loader": "^3.2.0",
"del-cli": "^3.0.0",
"electron": "^6.0.7",
"electron": "^6.0.8",
"electron-builder": "^21.2.0",
"electron-webpack": "^2.7.4",
"eslint": "^6.3.0",
2 changes: 1 addition & 1 deletion src/main/blockchain/InvitesHandler.js
Original file line number Diff line number Diff line change
@@ -133,7 +133,7 @@ export default class InvitesHandler {
this.logger.log({
level: 'debug',
message: 'Fetched invite events',
events: events.toString(),
events,
})

for (let i = 0; i < events.length; i++) {
14 changes: 11 additions & 3 deletions src/main/context/launcher.js
Original file line number Diff line number Diff line change
@@ -189,7 +189,6 @@ export class LauncherContext {
}

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

if (iterator.errors && iterator.errors.length > 0) {
this.logger.log({
level: 'error',
message: 'GraphQL subscription failed to create iterator',
errors: iterator.errors.map(e => e.toString()),
})
throw new Error('Failed to create subscription iterator')
}

const subscription = new GraphQLSubscription(iterator)
this._graphqlSubscriptions[subscription.id] = subscription

subscription.start(this.graphqlNotify).catch(error => {
subscription.start(this.graphqlNotify).catch(err => {
this.logger.log({
level: 'error',
message: 'GraphQL subscription notification failed',
error,
error: err.toString(),
})
delete this._graphqlSubscriptions[subscription.id]
})
23 changes: 10 additions & 13 deletions src/main/db/collections/contacts.js
Original file line number Diff line number Diff line change
@@ -200,19 +200,16 @@ export default async (
getFirstContactFeed(userAddress, peerAddress),
)

const payload = await encode(
sharedKey,
writeFirstContact({
contact: {
signature,
publicKey: this.keyPair.publicKey,
},
peer: {
publicFeed: userAddress,
},
}),
)

const firstContactData = await writeFirstContact({
contact: {
signature,
publicKey: this.keyPair.publicKey,
},
peer: {
publicFeed: userAddress,
},
})
const payload = await encode(sharedKey, firstContactData)
await feed.publishJSON(user.getBzz(), payload)

logger.log({
1 change: 1 addition & 0 deletions src/main/graphql/objects.js
Original file line number Diff line number Diff line change
@@ -950,6 +950,7 @@ export const lookup = new GraphQLObjectType({

export const lookupField = {
type: new GraphQLNonNull(lookup),
resolve: () => ({}),
}

export const systemUpdateStatus = new GraphQLEnumType({
32 changes: 31 additions & 1 deletion src/main/graphql/subscription.js
Original file line number Diff line number Diff line change
@@ -125,8 +125,15 @@ const contactChanged = {
},
}

const contactsChangedPayload = new GraphQLObjectType({
name: 'contactsChangedPayload',
fields: () => ({
viewer: viewerField,
}),
})

const contactsChanged = {
type: new GraphQLNonNull(contactChangedPayload),
type: new GraphQLNonNull(contactsChangedPayload),
subscribe: async (self, args, ctx: GraphQLContext) => {
const user = await ctx.getUser()
const observable = user.get$('contacts').pipe(
@@ -140,6 +147,28 @@ const contactsChanged = {
},
}

const contactRequestsChangedPayload = new GraphQLObjectType({
name: 'ContactRequestsChangedPayload',
fields: () => ({
viewer: viewerField,
}),
})

const contactRequestsChanged = {
type: new GraphQLNonNull(contactRequestsChangedPayload),
subscribe: async (self, args, ctx: GraphQLContext) => {
const user = await ctx.getUser()
const observable = user.get$('contactRequests').pipe(
map(() => ({
contactRequestsChanged: {
viewer: {},
},
})),
)
return observableToAsyncIterator(observable)
},
}

const systemUpdateChangedPayload = new GraphQLObjectType({
name: 'SystemUpdateChangedPayload',
fields: () => ({
@@ -170,6 +199,7 @@ export default new GraphQLObjectType({
appVersionChanged,
contactChanged,
contactsChanged,
contactRequestsChanged,
systemUpdateChanged,
}),
})
2 changes: 1 addition & 1 deletion src/renderer/launcher/CopyableBlock.js
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ const TextContainer = styled.View`
`

const ButtonContainer = styled.View`
padding: 20px;
padding: 10px;
`

type Props = {
46 changes: 14 additions & 32 deletions src/renderer/launcher/HomeRouter.js
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ import DevtoolsRouter from './devtools/DevtoolsRouter'
import SettingsRouter from './settings/SettingsRouter'
import WalletsScreen from './wallets/WalletsScreen'
import type { HomeRouterAppUpdatesChangedSubscriptionResponse as AppUpdatesData } from './__generated__/HomeRouterAppUpdatesChangedSubscription.graphql'
import type { HomeRouterContactRequestsChangedSubscriptionResponse as ContactRequestsData } from './__generated__/HomeRouterContactRequestsChangedSubscription.graphql'
import type { HomeRouterSystemUpdateChangedSubscriptionResponse as SystemUpdateData } from './__generated__/HomeRouterSystemUpdateChangedSubscription.graphql'

const APP_UPDATES_CHANGED_SUBSCRIPTION = graphql`
@@ -25,36 +26,12 @@ const APP_UPDATES_CHANGED_SUBSCRIPTION = graphql`
}
`

const APP_VERSION_CHANGED_SUBSCRIPTION = graphql`
subscription HomeRouterAppVersionChangedSubscription {
appVersionChanged {
appVersion {
...AppItem_appVersion
}
}
}
`

const CONTACT_CHANGED_SUBSCRIPTION = graphql`
subscription HomeRouterContactChangedSubscription {
contactChanged {
contact {
localID
peerID
publicID
connectionState
invite {
...InviteContactModal_contactInvite
ethNetwork
fromAddress
inviteTX
stakeState
stakeAmount
reclaimedStakeTX
}
profile {
name
ethAddress
const CONTACT_REQUESTS_CHANGED_SUBSCRIPTION = graphql`
subscription HomeRouterContactRequestsChangedSubscription {
contactRequestsChanged {
viewer {
contactRequests {
localID
}
}
}
@@ -94,8 +71,13 @@ export default function HomeRouter() {
useSubscription(APP_UPDATES_CHANGED_SUBSCRIPTION, (data: AppUpdatesData) => {
setBadges(b => ({ ...b, apps: data.appUpdatesChanged.appUpdatesCount > 0 }))
})
useSubscription(APP_VERSION_CHANGED_SUBSCRIPTION)
useSubscription(CONTACT_CHANGED_SUBSCRIPTION)
useSubscription(
CONTACT_REQUESTS_CHANGED_SUBSCRIPTION,
(data: ContactRequestsData) => {
const { contactRequests } = data.contactRequestsChanged.viewer
setBadges(b => ({ ...b, contacts: contactRequests.length > 0 }))
},
)
useSubscription(
SYSTEM_UPDATE_CHANGED_SUBSCRIPTION,
(data: SystemUpdateData) => {
Loading

0 comments on commit b2fec1d

Please sign in to comment.