Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Emit user notifications from chain events." #56

Merged
merged 1 commit into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,5 @@ jobs:
- run:
name: run api tests
command: yarn test-api
- run:
name: run event tests
command: yarn test-events
- store_artifacts:
path: coverage
7 changes: 1 addition & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@
"lines-between-class-members": 0,
"max-classes-per-file": ["error", 5],
"max-len": ["error", {"code": 120, "tabWidth": 2}],
"no-trailing-spaces": ["error"],
"no-useless-constructor": 0,
"no-empty-function": 0,
"import/prefer-default-export": 0,
"dot-notation": 0,
"no-lonely-if": 0
"dot-notation": 0
}
}
3 changes: 1 addition & 2 deletions client/scripts/controllers/chain/edgeware/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Edgeware extends IChainAdapter<SubstrateCoin, SubstrateAccount> {

await super.init(async () => {
const edgTypes = Object.values(edgewareDefinitions)
.reduce((res, { default: { types } }): object => ({ ...res, ...types }), {});
.reduce((res, { types }): object => ({ ...res, ...types }), {});

await this.chain.resetApi(this.meta, {
types: {
Expand All @@ -65,7 +65,6 @@ class Edgeware extends IChainAdapter<SubstrateCoin, SubstrateAccount> {
StakingLedger: 'StakingLedgerTo223',
Votes: 'VotesTo230',
ReferendumInfo: 'ReferendumInfoTo239',
Weight: 'u32',
},
// override duplicate type name
typesAlias: { voting: { Tally: 'VotingTally' } },
Expand Down
13 changes: 3 additions & 10 deletions client/scripts/controllers/chain/substrate/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,16 +386,9 @@ export class SubstrateAccount extends Account<SubstrateCoin> {
public get balanceTransferFee(): Observable<SubstrateCoin> {
if (this.chainClass === ChainClass.Edgeware) {
// grab const tx fee on edgeware
return from(this._Chain.api.pipe(map((api: ApiRx) => (api.consts.balances.transferFee as Balance)))
.toPromise()
.then((txFee) => {
if (txFee) {
return Promise.resolve(this._Chain.coins(txFee));
} else {
const dummyTxFunc = (api: ApiRx) => api.tx.balances.transfer(this.address, '0');
return this._Chain.computeFees(this.address, dummyTxFunc);
}
}));
return this._Chain.api.pipe(
map((api: ApiRx) => this._Chain.coins(api.consts.balances.transferFee as Balance))
);
} else {
// compute fee on Kusama
const dummyTxFunc = (api: ApiRx) => api.tx.balances.transfer(this.address, '0');
Expand Down
27 changes: 0 additions & 27 deletions client/scripts/models/ChainEvent.ts

This file was deleted.

19 changes: 0 additions & 19 deletions client/scripts/models/ChainEventType.ts

This file was deleted.

16 changes: 2 additions & 14 deletions client/scripts/models/Notification.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,33 @@
import moment from 'moment-twitter';
import NotificationSubscription from './NotificationSubscription';
import ChainEvent from './ChainEvent';

class Notification {
public readonly id: number;
public readonly data: string;
public readonly createdAt: moment.Moment;
public readonly subscription: NotificationSubscription;
public readonly chainEvent?: ChainEvent;

private _isRead: boolean;
public get isRead(): boolean {
return this._isRead;
}

constructor(id, data, isRead, createdAt, subscription, chainEvent?) {
constructor(id, data, isRead, createdAt, subscription) {
this.id = id;
this.data = data;
this._isRead = isRead;
this.createdAt = moment(createdAt);
this.subscription = subscription;
this.chainEvent = chainEvent;
}

public markRead() {
if (this._isRead) {
throw new Error('notification already read!');
} else {
this._isRead = true;
}
}

public static fromJSON(json, subscription: NotificationSubscription) {
return new Notification(
json.id,
json.notification_data,
json.is_read,
json.created_at,
subscription,
json.ChainEvent ? ChainEvent.fromJSON(json.ChainEvent) : undefined,
);
return new Notification(json.id, json.notification_data, json.is_read, json.created_at, subscription);
}
}

Expand Down
2 changes: 0 additions & 2 deletions client/scripts/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ export { default as StorageModule } from './StorageModule';
export { default as ChainObject } from './ChainObject';
export { default as ChainObjectQuery } from './ChainObjectQuery';
export { default as ChainObjectVersion } from './ChainObjectVersion';
export { default as ChainEventType } from './ChainEventType';
export { default as ChainEvent } from './ChainEvent';

export { DepositVote, BinaryVote } from './votes';

Expand Down
87 changes: 33 additions & 54 deletions client/scripts/views/components/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@ import $ from 'jquery';
import _ from 'lodash';
import moment from 'moment';
import mixpanel from 'mixpanel-browser';
import BN from 'bn.js';

import { initAppState } from 'app';
import app, { ApiStatus } from 'state';
import { ProposalType } from 'identifiers';
import { featherIcon, slugify } from 'helpers';
import { NotificationCategories } from 'types';

import { formatCoin } from 'adapters/currency';
import labelEdgewareEvent from 'events/edgeware/filters/labeler';

import Substrate from 'controllers/chain/substrate/main';
import Cosmos from 'controllers/chain/cosmos/main';
import Edgeware from 'controllers/chain/edgeware/main';
Expand Down Expand Up @@ -615,52 +610,36 @@ const HeaderNotificationRow: m.Component<IHeaderNotificationRow> = {
]);
};

if (category === NotificationCategories.ChainEvent) {
if (!notification.chainEvent) {
throw new Error('chain event notification does not have expected data');
}
// TODO: use different labelers depending on chain
const label = labelEdgewareEvent(
notification.chainEvent.blockNumber,
notification.chainEvent.type.chain,
notification.chainEvent.data,
);
return m('li.HeaderNotificationRow', {
class: notification.isRead ? '' : 'active',
onclick: async () => {
const notificationArray: Notification[] = [];
notificationArray.push(notification);
app.login.notifications.markAsRead(notificationArray).then(() => m.redraw());
if (!label.linkUrl) return;
await m.route.set(label.linkUrl);
m.redraw.sync();
},
}, [
m('.comment-body', [
m('.comment-body-top', label.heading),
m('.comment-body-bottom', `Block ${notification.chainEvent.blockNumber}`),
m('.comment-body-excerpt', label.label),
]),
]);
} else {
const {
author,
createdAt,
notificationHeader,
notificationBody,
path,
pageJump
} = getNotificationFields(category, JSON.parse(notification.data));

return getHeaderNotificationRow(
author,
createdAt,
notificationHeader,
notificationBody,
path,
pageJump
);
}
const {
author,
createdAt,
notificationHeader,
notificationBody,
path,
pageJump
} = getNotificationFields(category, JSON.parse(notification.data));

return getHeaderNotificationRow(
author,
createdAt,
notificationHeader,
notificationBody,
path,
pageJump
);

// else if (category === NotificationCategories.NewCommunity) {
// //const { created_at, proposal_id } = JSON.parse(notification.data);
// //const thread = app.threads.store.getByIdentifier(proposal_id);
// const community = app.activeId();

// return getHeaderNotificationRow(
// moment.utc(created_at),
// null,
// `New community created`,
// '',
// `/${community}/`);
// }
},
};

Expand Down Expand Up @@ -716,7 +695,6 @@ const NotificationButtons: m.Component<{ notifications }> = {
const { notifications } = vnode.attrs;
return m('.NotificationButtons', [
m('.button', {
class: notifications.length > 0 ? '' : 'disabled',
onclick: (e) => {
e.preventDefault();
if (notifications.length < 1) return;
Expand Down Expand Up @@ -748,8 +726,9 @@ const NotificationMenu : m.Component<{ menusOpen }> = {
class: (unreadCount > 0 || invites.length > 0) ? 'unread-notifications' : '',
}, unreadMessage),
}, [
notifications.length > 0 && m(NotificationButtons, { notifications }),
m(Notifications, { notifications }),
notifications.length > 0
&& m(NotificationButtons, { notifications }),
]);
}
};
Expand Down Expand Up @@ -784,7 +763,7 @@ const Header: m.Component<{}, IHeaderState> = {
e.preventDefault();
e.stopPropagation();
$(e.target).trigger('menuclose');
m.route.set(app.login.selectedNode ? `/${app.login.selectedNode.chain.id || app.login.selectedNode.chain}/` : '/');
m.route.set(app.login.selectedNode ? `/${app.login.selectedNode.chain.id}/` : '/');
},
}, [
m('.header-logo-image')
Expand Down
21 changes: 9 additions & 12 deletions client/scripts/views/components/settings/send_edg_well.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,16 @@ const getBalanceTransferChecks = (
`Transfer fee: ${formatCoin(txFee)}`
]);
}

const creationFee = (app.chain as Substrate).chain.creationfee;
if (canTransfer && recipientBalance.eqn(0) && creationFee) {
if (creationFee.gtn(0)) {
checks.push([
featherIcon('info', 14, 2, '#444'),
`Account creation fee: ${formatCoin((app.chain as Substrate).chain.creationfee)}`
]);
}
if (canTransfer && recipientBalance.eqn(0) && (app.chain as Substrate).chain.creationfee.gtn(0)) {
checks.push([
featherIcon('info', 14, 2, '#444'),
`Account creation fee: ${formatCoin((app.chain as Substrate).chain.creationfee)}`
]);
}
const resultingBalance = app.chain.chain.coins(recipientBalance.add(recipientBalance.gtn(0)
? amount.sub(txFee)
: (creationFee) ? amount.sub(txFee).sub(creationFee) : amount.sub(txFee)));
const resultingBalance = app.chain.chain.coins(recipientBalance.add(recipientBalance.gtn(0) ?
amount.sub(txFee) :
amount.sub(txFee)
.sub((app.chain as Substrate).chain.creationfee)));
if (recipientBalance.eqn(0) && resultingBalance.lt((app.chain as Substrate).chain.existentialdeposit)) {
checks.push([
featherIcon('slash', 14, 2, '#444'),
Expand Down
Loading