-
Notifications
You must be signed in to change notification settings - Fork 137
feat: add optional [community] param to /buy and /sell commands #879
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ import * as ordersActions from '../../ordersActions'; | |
| import { deletedCommunityMessage } from './messages'; | ||
| import { | ||
| getCommunityInfo, | ||
| getCommunityByIdentifier, | ||
| isCurrencySupported, | ||
| } from '../../../util/communityHelper'; | ||
| import { takebuy, takesell, takebuyValidation } from './takeOrder'; | ||
|
|
@@ -50,18 +51,15 @@ const sell = async (ctx: MainContext) => { | |
| const sellOrderParams = await validateSellOrder(ctx); | ||
|
|
||
| if (!sellOrderParams) return; | ||
| const { amount, fiatAmount, fiatCode, paymentMethod } = sellOrderParams; | ||
| const { amount, fiatAmount, fiatCode, paymentMethod, communityName } = | ||
| sellOrderParams; | ||
| let priceMargin = sellOrderParams.priceMargin; | ||
| priceMargin = isFloat(priceMargin) | ||
| ? parseFloat(priceMargin.toFixed(2)) | ||
| : parseInt(priceMargin); | ||
|
|
||
| // Optimized community lookup - single database query instead of multiple | ||
| const communityInfo = await getCommunityInfo( | ||
| user, | ||
| ctx.message?.chat.type || 'private', | ||
| ctx.message?.chat as Chat.UserNameChat, | ||
| ); | ||
| const communityInfo = await resolveOrderCommunity(ctx, user, communityName); | ||
| if (!communityInfo) return; | ||
|
|
||
| const { community, communityId, isBanned } = communityInfo; | ||
|
|
||
|
|
@@ -119,18 +117,15 @@ const buy = async (ctx: MainContext) => { | |
| const buyOrderParams = await validateBuyOrder(ctx); | ||
| if (!buyOrderParams) return; | ||
|
|
||
| const { amount, fiatAmount, fiatCode, paymentMethod } = buyOrderParams; | ||
| const { amount, fiatAmount, fiatCode, paymentMethod, communityName } = | ||
| buyOrderParams; | ||
| let priceMargin = buyOrderParams.priceMargin; | ||
| priceMargin = isFloat(priceMargin) | ||
| ? parseFloat(priceMargin.toFixed(2)) | ||
| : parseInt(priceMargin); | ||
|
|
||
| // Optimized community lookup - single database query instead of multiple | ||
| const communityInfo = await getCommunityInfo( | ||
| user, | ||
| ctx.message?.chat.type || 'private', | ||
| ctx.message?.chat as Chat.UserNameChat, | ||
| ); | ||
| const communityInfo = await resolveOrderCommunity(ctx, user, communityName); | ||
| if (!communityInfo) return; | ||
|
|
||
| const { community, communityId, isBanned } = communityInfo; | ||
|
|
||
|
|
@@ -182,6 +177,37 @@ const buy = async (ctx: MainContext) => { | |
| } | ||
| }; | ||
|
|
||
| // Decides which community an order should be published to. | ||
| // When the user passes a community name in a private chat, the order is | ||
| // published to that community. Otherwise the default behaviour applies: the | ||
| // group's community when the command runs inside a group, or the user's | ||
| // default community in private. Returns null when the flow must stop because | ||
| // an error was already reported to the user. | ||
| async function resolveOrderCommunity( | ||
| ctx: MainContext, | ||
| user: UserDocument, | ||
| communityName?: string, | ||
| ) { | ||
| const isPrivate = (ctx.message?.chat.type || 'private') === 'private'; | ||
|
|
||
| // The community name is only honored in private chats; inside a group the | ||
| // group's own community always wins. | ||
| if (communityName && isPrivate) { | ||
| const communityInfo = await getCommunityByIdentifier(user, communityName); | ||
| if (!communityInfo.community) { | ||
| await ctx.reply(ctx.i18n.t('community_not_found')); | ||
| return null; | ||
| } | ||
| return communityInfo; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Blocking scope mismatch: this returns a single resolved destination, and each handler calls
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR intentionally publishes to a single destination. Double-publishing to two communities at once was considered too complex and out of scope. The [community] param lets the user choose the destination explicitly; publishing to a second community means running the command again. We're realigning the scope: this PR does not fully close #877, it delivers the optional-community parameter only. |
||
| } | ||
|
|
||
| return getCommunityInfo( | ||
| user, | ||
| ctx.message?.chat.type || 'private', | ||
| ctx.message?.chat as Chat.UserNameChat, | ||
| ); | ||
| } | ||
|
|
||
| async function enterWizard( | ||
| ctx: CommunityContext, | ||
| user: UserDocument, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.