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

Remove token balance requirement for creating threads #1220

Merged
merged 3 commits into from
Jun 9, 2021
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
12 changes: 4 additions & 8 deletions client/scripts/views/components/new_proposal_button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ export const MobileNewProposalButton: m.Component<{}, { councilCandidates?: Arra
hoverCloseDelay: 0,
hasArrow: false,
trigger: m(Button, {
disabled: !app.user.activeAccount
|| (app.activeChainId() && (app.chain as Token).isToken && !(app.chain as Token).hasToken),
disabled: !app.user.activeAccount,
label: m(Icon, { name: Icons.PLUS }),
}),
inline: true,
Expand Down Expand Up @@ -109,8 +108,7 @@ const NewProposalButton: m.Component<{
class: 'NewProposalButton',
label: 'New thread',
fluid,
disabled: !app.user.activeAccount
|| (app.chain && (app.chain as Token).isToken && !(app.chain as Token).hasToken),
disabled: !app.user.activeAccount,
onclick: () => app.modals.create({ modal: NewThreadModal }),
});
}
Expand All @@ -124,8 +122,7 @@ const NewProposalButton: m.Component<{
hoverCloseDelay: 0,
hasArrow: false,
trigger: m(Button, {
disabled: !app.user.activeAccount
|| ((app.chain as Token).isToken && !(app.chain as Token).hasToken),
disabled: !app.user.activeAccount,
label: 'New thread',
}),
position: 'bottom-end',
Expand All @@ -136,8 +133,7 @@ const NewProposalButton: m.Component<{
content: getNewProposalMenu(councilCandidates),
}),
m(Button, {
disabled: !app.user.activeAccount
|| ((app.chain as Token).isToken && !(app.chain as Token).hasToken),
disabled: !app.user.activeAccount,
iconLeft: Icons.EDIT,
fluid,
onclick: () => app.modals.create({ modal: NewThreadModal }),
Expand Down
3 changes: 1 addition & 2 deletions client/scripts/views/pages/view_proposal/create_comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ const CreateComment: m.Component<{
intent: 'primary',
type: 'submit',
compact: true,
disabled: getSetGlobalEditingStatus(GlobalStatus.Get) || sendingComment || uploadsInProgress > 0
|| (app.activeChainId() && (app.chain as Token).isToken && !(app.chain as Token).hasToken),
disabled: getSetGlobalEditingStatus(GlobalStatus.Get) || sendingComment || uploadsInProgress > 0,
rounded: true,
onclick: submitComment,
label: (uploadsInProgress > 0)
Expand Down
19 changes: 0 additions & 19 deletions server/routes/createComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,6 @@ const createComment = async (
if (error) return next(new Error(error));
const [author, authorError] = await lookupAddressIsOwnedByUser(models, req);
if (authorError) return next(new Error(authorError));
if (chain && chain.type === 'token') {
// skip check for admins
const isAdmin = await models.Role.findAll({
where: {
address_id: author.id,
chain_id: chain.id,
permission: ['admin'],
},
});
if (isAdmin.length === 0) {
try {
const userHasBalance = await tokenBalanceCache.hasToken(chain.id, req.body.address);
if (!userHasBalance) return next(new Error(Errors.InsufficientTokenBalance));
} catch (e) {
log.error(`hasToken failed: ${e.message}`);
return next(new Error(Errors.CouldNotFetchTokenBalance));
}
}
}

const { parent_id, root_id, text } = req.body;

Expand Down
19 changes: 0 additions & 19 deletions server/routes/createReaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,6 @@ const createReaction = async (
if (error) return next(new Error(error));
const [author, authorError] = await lookupAddressIsOwnedByUser(models, req);
if (authorError) return next(new Error(authorError));
if (chain && chain.type === 'token') {
// skip check for admins
const isAdmin = await models.Role.findAll({
where: {
address_id: author.id,
chain_id: chain.id,
permission: ['admin'],
},
});
if (isAdmin.length === 0) {
try {
const userHasBalance = await tokenBalanceCache.hasToken(chain.id, req.body.address);
if (!userHasBalance) return next(new Error(Errors.InsufficientTokenBalance));
} catch (e) {
log.error(`hasToken failed: ${e.message}`);
return next(new Error(Errors.CouldNotFetchTokenBalance));
}
}
}

const { reaction, comment_id, proposal_id, thread_id } = req.body;
let proposal;
Expand Down
19 changes: 0 additions & 19 deletions server/routes/createThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,6 @@ const createThread = async (
if (error) return next(new Error(error));
const [author, authorError] = await lookupAddressIsOwnedByUser(models, req);
if (authorError) return next(new Error(authorError));
if (chain && chain.type === 'token') {
// skip check for admins
const isAdmin = await models.Role.findAll({
where: {
address_id: author.id,
chain_id: chain.id,
permission: ['admin'],
},
});
if (isAdmin.length === 0) {
try {
const userHasBalance = await tokenBalanceCache.hasToken(chain.id, req.body.address);
if (!userHasBalance) return next(new Error(Errors.InsufficientTokenBalance));
} catch (e) {
log.error(`hasToken failed: ${e.message}`);
return next(new Error(Errors.CouldNotFetchTokenBalance));
}
}
}

const { topic_name, topic_id, title, body, kind, stage, url, readOnly } = req.body;

Expand Down