-
Notifications
You must be signed in to change notification settings - Fork 8
feat(client): scope the securities trade counterparty picker to securities #4258
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| --- | ||
| '@accounter/client': minor | ||
| --- | ||
|
|
||
| Offer securities, and only securities, as the counterparty of a foreign-securities trade. | ||
|
|
||
| The main transaction of a securities charge settles against the security it traded, so the picker | ||
| that appears when it has no counterparty yet now lists the tenant's security businesses plus the | ||
| general foreign-securities business — the fallback for a trade whose security cannot be told — rather | ||
| than the whole business directory, where the right answer is a needle in a haystack and a wrong one | ||
| is one click away. Each option carries its ISIN, which is what tells two share classes of one issuer | ||
| apart. | ||
|
|
||
| The fee row is the bank's and keeps the full list, matching what the suggestion resolver does on the | ||
| server. | ||
|
|
||
| The rule is decided client-side from what the charge already knows, so `chargeType` — typed as the | ||
| shared `ChargeType` union rather than a bare string, since it is compared against typename literals — | ||
| is threaded from `charge-extended-info` through `ChargeTransactionsTable` and `TransactionsTable` | ||
| onto the row, the same way `enableEdit` and `enableChargeLink` are. The other `TransactionsTable` | ||
| callers pass no charge type and are unaffected: `useGetSecurityBusinesses` takes a `pause` flag, so a | ||
| plain transactions table does not run the securities query once per row for a list it never shows. | ||
|
|
||
| `UserContext.foreignSecuritiesBusinessId` is read through the user provider for that fallback option, | ||
| and `useGetSecurityBusinesses` is the securities-scoped counterpart of `useGetAdminBusinesses`. | ||
|
|
||
| The suggestion itself needs no client change: the cell already pre-seeds the select from | ||
| `missingInfoSuggestions`, which now resolves the security named in the trade's description. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import { useEffect, useMemo } from 'react'; | ||
| import { toast } from 'sonner'; | ||
| import { useQuery } from 'urql'; | ||
| import { AllSecurityBusinessesDocument, type AllSecurityBusinessesQuery } from '../gql/graphql.js'; | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- used by codegen | ||
| /* GraphQL */ ` | ||
| query AllSecurityBusinesses { | ||
| allSecurityBusinesses { | ||
| id | ||
| name | ||
| securityInfo { | ||
| id | ||
| isin | ||
| symbol | ||
| } | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| export type SecurityBusinesses = NonNullable<AllSecurityBusinessesQuery['allSecurityBusinesses']>; | ||
|
|
||
| type UseGetSecurityBusinesses = { | ||
| fetching: boolean; | ||
| refresh: () => void; | ||
| securityBusinesses: SecurityBusinesses; | ||
| selectableSecurityBusinesses: Array<{ value: string; label: string }>; | ||
| }; | ||
|
|
||
| type UseGetSecurityBusinessesOptions = { | ||
| /** Skips the query entirely — for callers that only need the list in some rows. */ | ||
| pause?: boolean; | ||
| }; | ||
|
|
||
| /** | ||
| * The businesses that stand for a traded security, for pickers that should offer only those — | ||
| * the counterparty of a foreign-securities trade, above all. | ||
| * | ||
| * Pausable because its caller is a table cell: a plain transactions table would otherwise run | ||
| * this query once per row for a list it never shows. | ||
| */ | ||
| export const useGetSecurityBusinesses = ({ | ||
| pause, | ||
| }: UseGetSecurityBusinessesOptions = {}): UseGetSecurityBusinesses => { | ||
| const [{ data, fetching, error }, fetch] = useQuery({ | ||
| query: AllSecurityBusinessesDocument, | ||
| pause, | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| if (error) { | ||
| console.error(`Error fetching security businesses: ${error}`); | ||
| toast.error('Error', { | ||
| description: 'Unable to fetch security businesses', | ||
| }); | ||
| } | ||
| }, [error]); | ||
|
|
||
| const securityBusinesses = useMemo(() => { | ||
| return data?.allSecurityBusinesses?.slice().sort((a, b) => a.name.localeCompare(b.name)) ?? []; | ||
| }, [data]); | ||
|
|
||
| const selectableSecurityBusinesses = useMemo(() => { | ||
| return securityBusinesses.map(business => ({ | ||
| value: business.id, | ||
| // The ISIN is what makes two share classes of one issuer tellable apart. | ||
| label: business.securityInfo?.isin | ||
| ? `${business.name} · ${business.securityInfo.isin}` | ||
| : business.name, | ||
| })); | ||
| }, [securityBusinesses]); | ||
|
|
||
| return { | ||
| fetching, | ||
| refresh: () => fetch(), | ||
| securityBusinesses, | ||
| selectableSecurityBusinesses, | ||
| }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.