Skip to content

Commit

Permalink
refactor signIn, notifications (#1054)
Browse files Browse the repository at this point in the history
* refactor(signIn, notifications): force ntw check; split world notif sender

* refactor(newNotifs): stop at first new message
  • Loading branch information
kenshyx authored Apr 7, 2021
1 parent 2f9d761 commit 8c156a3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions api/hub/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ AWF_FAUCET_KEY=
AWF_FAUCET_SECRET=
AWF_FAUCET_NETWORK=

AWF_MAILSENDER_KEY=

ALLOWED_ORIGINS=
3 changes: 2 additions & 1 deletion api/hub/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const newClientDB = async () => {
return client;
};
const identity = () => PrivateKey.fromString(process.env.AWF_DBkey);
const mailSenderIdentity = () => PrivateKey.fromString(process.env.AWF_MAILSENDER_KEY);
let appDBClient;
export const getAppDB = async () => {
if (appDBClient) {
Expand Down Expand Up @@ -75,7 +76,7 @@ export const getMailSender = async () => {
await createUserAuth(process.env.USER_GROUP_API_KEY, process.env.USER_GROUP_API_SECRET),
{ debug: process.env.NODE_ENV !== 'production' },
);
const mailSenderID = identity();
const mailSenderID = mailSenderIdentity();
await api.getToken(mailSenderID);
await api.setupMailbox();
// const mailID = await api.getMailboxID();
Expand Down
3 changes: 2 additions & 1 deletion sdk-packages/akasha/webpack.dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const config = {
INVITATION_ENDPOINT: process.env.INVITATION_ENDPOINT || 'https://staging-api.ethereum.world/api/validate-token',
AUTH_ENDPOINT: process.env.AUTH_ENDPOINT || 'wss://staging-api.ethereum.world/ws/userauth',
INFURA_ID: process.env.INFURA_ID || '',
BUCKET_VERSION: process.env.BUCKET_VERSION || ''
BUCKET_VERSION: process.env.BUCKET_VERSION || '',
EWA_MAILSENDER: process.env.EWA_MAILSENDER || ''
}),
new webpack.ProgressPlugin({
entries: true,
Expand Down
9 changes: 7 additions & 2 deletions sdk-packages/auth/src/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ const service: AkashaService = (invoke, log, globalChannel) => {
try {
const web3 = await invoke(commonServices[WEB3_SERVICE]).regen(currentProvider);
const web3Utils = await invoke(commonServices[WEB3_UTILS_SERVICE]).getUtils();

// throw if the current network is not the one from settings
await invoke(commonServices[WEB3_SERVICE]).checkCurrentNetwork();
const { getSettings } = invoke(coreServices.SETTINGS_SERVICE);
const authSettings = await getSettings(moduleName);
const endPoint = authSettings[AUTH_ENDPOINT];
Expand Down Expand Up @@ -391,6 +392,9 @@ const service: AkashaService = (invoke, log, globalChannel) => {
const inbox = [];
const uniqueMessages = new Map();
for (const messageObj of combinedMessages) {
if (messageObj.from !== process.env.EWA_MAILSENDER) {
continue;
}
uniqueMessages.set(messageObj.id, messageObj);
}
for (const message of uniqueMessages.values()) {
Expand All @@ -404,7 +408,8 @@ const service: AkashaService = (invoke, log, globalChannel) => {
const hasNewNotifications = async () => {
const limit = 1;
const messages = await hubUser.listInboxMessages({ status: Status.UNREAD, limit: limit });
return messages.length > 0;
const newMessage = messages.find(rec => rec.from === process.env.EWA_MAILSENDER);
return !!newMessage;
};
const markMessageAsRead = async (messageId: string) => {
await hubUser.readInboxMessage(messageId);
Expand Down
3 changes: 2 additions & 1 deletion ui/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ module.exports = {
new webpack.EnvironmentPlugin({
MODERATION_API: process.env.MODERATION_API || 'https://staging-moderation.ethereum.world',
INFURA_ID: process.env.INFURA_ID || '',
BUCKET_VERSION: process.env.BUCKET_VERSION || ''
BUCKET_VERSION: process.env.BUCKET_VERSION || '',
EWA_MAILSENDER: process.env.EWA_MAILSENDER || ''
}),
new webpack.AutomaticPrefetchPlugin(),
new webpack.ProgressPlugin({
Expand Down

0 comments on commit 8c156a3

Please sign in to comment.