-
-
Notifications
You must be signed in to change notification settings - Fork 276
feat: adds support for custom actions #8100
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
base: main
Are you sure you want to change the base?
Changes from all commits
58ba273
292cc29
0e5806f
c8b29e7
77032d8
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 |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import type { Json } from '@metamask/utils'; | |
| import type { Draft } from 'immer'; | ||
|
|
||
| import type { | ||
| BuyWidget, | ||
| Country, | ||
| TokensResponse, | ||
| Provider, | ||
|
|
@@ -259,9 +260,8 @@ export type RampsControllerState = { | |
| */ | ||
| nativeProviders: NativeProvidersState; | ||
| /** | ||
| * V2 orders stored directly as RampsOrder[]. | ||
| * The controller is the authority for V2 orders — it polls, updates, | ||
| * and persists them. No FiatOrder wrapper needed. | ||
| * and persists them. | ||
| */ | ||
| orders: RampsOrder[]; | ||
| }; | ||
|
|
@@ -623,6 +623,10 @@ function findRegionFromCode( | |
| }; | ||
| } | ||
|
|
||
| export function normalizeProviderCode(providerCode: string): string { | ||
| return providerCode.replace(/^\/providers\//u, ''); | ||
| } | ||
|
|
||
| // === ORDER POLLING CONSTANTS === | ||
|
|
||
| const TERMINAL_ORDER_STATUSES = new Set<RampsOrderStatus>([ | ||
|
|
@@ -1707,7 +1711,7 @@ export class RampsController extends BaseController< | |
| return; | ||
| } | ||
|
|
||
| const providerCodeSegment = providerCode.replace('/providers/', ''); | ||
| const providerCodeSegment = normalizeProviderCode(providerCode); | ||
| const previousStatus = order.status; | ||
|
|
||
| try { | ||
|
|
@@ -1834,28 +1838,84 @@ export class RampsController extends BaseController< | |
| } | ||
|
|
||
| /** | ||
| * Fetches the widget URL from a quote for redirect providers. | ||
| * Fetches the widget data from a quote for redirect providers. | ||
| * Makes a request to the buyURL endpoint via the RampsService to get the | ||
| * actual provider widget URL. | ||
| * actual provider widget URL and optional order ID for polling. | ||
| * | ||
| * @param quote - The quote to fetch the widget URL from. | ||
| * @returns Promise resolving to the widget URL string, or null if not available. | ||
| * @returns Promise resolving to the full BuyWidget (url, browser, orderId), or null if not available (missing buyURL or empty url in response). | ||
| * @throws Rethrows errors from the RampsService (e.g. HttpError, network failures) so clients can react to fetch failures. | ||
| */ | ||
| async getWidgetUrl(quote: Quote): Promise<string | null> { | ||
| async getBuyWidgetData(quote: Quote): Promise<BuyWidget | null> { | ||
| const buyUrl = quote.quote?.buyURL; | ||
| if (!buyUrl) { | ||
| return null; | ||
| } | ||
|
|
||
| try { | ||
| const buyWidget = await this.messenger.call( | ||
| 'RampsService:getBuyWidgetUrl', | ||
| buyUrl, | ||
| ); | ||
| return buyWidget.url ?? null; | ||
| } catch { | ||
| const buyWidget = await this.messenger.call( | ||
| 'RampsService:getBuyWidgetUrl', | ||
| buyUrl, | ||
| ); | ||
| if (!buyWidget?.url) { | ||
| return null; | ||
| } | ||
| return buyWidget; | ||
| } | ||
|
|
||
| /** | ||
| * Registers an order ID for polling until the order is created or resolved. | ||
| * Adds a minimal stub order to controller state; the existing order polling | ||
| * will fetch the full order when the provider has created it. | ||
| * | ||
| * @param params - Object containing order identifiers and wallet info. | ||
| * @param params.orderId - Full order ID (e.g. "/providers/paypal/orders/abc123") or order code. | ||
| * @param params.providerCode - Provider code (e.g. "paypal", "transak"), with or without /providers/ prefix. | ||
| * @param params.walletAddress - Wallet address for the order. | ||
| * @param params.chainId - Optional chain ID for the order. | ||
| */ | ||
| addPrecreatedOrder(params: { | ||
| orderId: string; | ||
| providerCode: string; | ||
| walletAddress: string; | ||
| chainId?: string; | ||
| }): void { | ||
| const { orderId, providerCode, walletAddress, chainId } = params; | ||
|
|
||
| const orderCode = orderId.includes('/orders/') | ||
| ? orderId.split('/orders/')[1] | ||
| : orderId; | ||
|
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. Split parsing can yield undefined orderCode silentlyLow Severity When |
||
| const normalizedProviderCode = normalizeProviderCode(providerCode); | ||
|
|
||
|
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. This providerCode normalization (stripping /providers/) is also done in BuildQuote.tsx before calling addPrecreatedOrder. Two copies of the same logic means they can drift apart. Worth extracting into a shared util. |
||
| const stubOrder: RampsOrder = { | ||
| providerOrderId: orderCode, | ||
| provider: { | ||
| id: `/providers/${normalizedProviderCode}`, | ||
| name: '', | ||
| environmentType: '', | ||
| description: '', | ||
| hqAddress: '', | ||
| links: [], | ||
| logos: { light: '', dark: '', height: 0, width: 0 }, | ||
| }, | ||
| walletAddress, | ||
| status: RampsOrderStatus.Precreated, | ||
| orderType: 'buy', | ||
| createdAt: Date.now(), | ||
| isOnlyLink: false, | ||
| success: false, | ||
| cryptoAmount: 0, | ||
| fiatAmount: 0, | ||
| providerOrderLink: '', | ||
| totalFeesFiat: 0, | ||
| txHash: '', | ||
| network: chainId ? { chainId, name: '' } : { chainId: '', name: '' }, | ||
| canBeUpdated: true, | ||
| idHasExpired: false, | ||
| excludeFromPurchases: false, | ||
| timeDescriptionPending: '', | ||
| }; | ||
|
|
||
| this.addOrder(stubOrder); | ||
| } | ||
|
|
||
| /** | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The catch here swallows everything silently. From the caller's perspective it just returns null and there's no way to know if it was a missing buyURL or a failed network request. Worth at least logging the error before returning null.