@pollar/react 0.12.1-rc.6 → 0.12.1-rc.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,6 +13,10 @@ Stellar and Solana applications.
13
13
  > offers a network picker when the user holds a wallet on Stellar and Solana, and funds the card from a co-signed
14
14
  > wallet too. The email code input takes an autofilled one-time code. The ramp widget says a route's minimum or
15
15
  > maximum and offers "Change amount", and an order whose price changed before anything moved offers "Get a new quote".
16
+ > `openRampModal(options)` opens the ramp widget on a direction, country, fiat, asset and amount; the send, swap, earn,
17
+ > receive, history and card modals take options too, with `onSuccess` / `onFunded` callbacks.
18
+ > `<PollarProvider language>` and `client.setLocale()` switch the modals' language at runtime, open ones included. The
19
+ > ramp widget names each country in the modal's language.
16
20
  > A hook built with `createPollarAdapterHook` signs the auth entry an adapter answers with, without submitting
17
21
  > anything, and hands it to the adapter's `complete`.
18
22
  >
@@ -108,6 +112,7 @@ Context provider that initialises the Pollar client and makes it available to ch
108
112
  | Prop | Type | Required | Description |
109
113
  | ------------------ | ------------------------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
110
114
  | `client` | `PollarClient \| PollarClientConfig` | Yes | Either a pre-built `PollarClient` (testing, reuse outside React) or a `PollarClientConfig` the provider will construct one from. **Locked at first render** - swapping after mount is ignored |
115
+ | `language` | `string` | No | The modals' language, a BCP 47 tag (`'es'`, `'pt-BR'`): typically the app's current language. Followed on every render, so open modals switch when it changes. See [Language](#language) |
111
116
  | `appConfig` | `PollarConfig` | No | Local replacement for `/applications/config`, used verbatim and never merged with the server's answer. **Presence is the opt-out switch**: pass it and the remote fetch is skipped. Omit it to fetch the config on mount, which keeps branding, login methods and chains current. Unlike `client`, it can be added or swapped after mount - the context re-applies it (compared by value, so an inline object literal is fine) |
112
117
  | `adapters` | `PollarAdapters` | No | Named set of `PollarAdapter` objects (e.g. Trustless Work). See [Custom adapters](#custom-adapters) |
113
118
  | `onStorageDegrade` | `OnStorageDegrade` | No | Called once when persistent storage falls back to in-memory mode (Safari private browsing, sandboxed iframes), so the session will not survive a reload |
@@ -174,7 +179,7 @@ const {
174
179
 
175
180
  // Transaction history
176
181
  txHistory, // TxHistoryState
177
- openTxHistoryModal, // () => void
182
+ openTxHistoryModal, // (options?: TxHistoryModalOptions) => void
178
183
 
179
184
  // Wallet balance
180
185
  walletBalance, // WalletBalanceState
@@ -195,7 +200,7 @@ const {
195
200
  getSolanaSwapConfig, // () => Promise<SolanaSwapVenue[]> (Jupiter, Titan; mainnet)
196
201
  getSolanaSwapQuote, // (params: SolanaSwapQuoteParams) => Promise<SolanaSwapQuote[]>
197
202
  swapSolana, // (quote: SolanaSwapQuote, opts?: { slippageBps? }) => Promise<SubmitOutcome>
198
- openSwapModal, // () => void
203
+ openSwapModal, // (options?: SwapModalOptions) => void
199
204
 
200
205
  // Earn (yield vaults + lending - DeFindex + Blend)
201
206
  getEarnProviders, // () => Promise<EarnProviderId[]> ([] means Earn is disabled)
@@ -203,17 +208,17 @@ const {
203
208
  getEarnPosition, // (params: EarnPositionParams) => Promise<EarnPosition>
204
209
  earnDeposit, // (params: EarnTxParams) => Promise<SubmitOutcome>
205
210
  earnWithdraw, // (params: EarnTxParams) => Promise<SubmitOutcome>
206
- openEarnModal, // () => void
211
+ openEarnModal, // (options?: EarnModalOptions) => void
207
212
 
208
213
  // Cards (the card calls live on getClient(): getCardProviders, issueCard, fundCard, ...)
209
- openCardModal, // () => void
214
+ openCardModal, // (options?: CardModalOptions) => void
210
215
 
211
216
  // Distribution rules
212
217
  openDistributionRulesModal, // () => void
213
218
 
214
219
  // Send / Receive
215
- openSendModal, // () => void
216
- openReceiveModal, // () => void
220
+ openSendModal, // (options?: SendModalOptions) => void
221
+ openReceiveModal, // (options?: ReceiveModalOptions) => void
217
222
 
218
223
  // Network
219
224
  network, // StellarNetwork - 'mainnet' | 'testnet'
@@ -223,7 +228,7 @@ const {
223
228
  openKycModal, // (options?: { corridorId?, providerId?, country?, level?, onApproved? }) => void
224
229
 
225
230
  // Ramp (fiat on/off-ramps on the v3 ramps API, wired through core)
226
- openRampModal, // () => void
231
+ openRampModal, // (options?: RampModalOptions) => void
227
232
 
228
233
  // App config / styles served by the Pollar API
229
234
  appConfig, // PollarConfig
@@ -237,6 +242,60 @@ const {
237
242
  Custody is derived from `wallet`, not a separate field - e.g.
238
243
  `wallet?.custody === 'external' ? wallet.provider : null`.
239
244
 
245
+ #### Ramp options
246
+
247
+ `openRampModal()` opens the ramp widget on its defaults. `openRampModal(options)` opens it on a direction, country,
248
+ fiat, asset and amount; the user can still change each one.
249
+
250
+ ```ts
251
+ import type { RampModalOptions } from '@pollar/react';
252
+
253
+ openRampModal({ country: 'BR', direction: flow === 'withdraw' ? 'sell' : 'buy' });
254
+ openRampModal({ direction: 'buy', country: 'MX', fiat: 'MXN', asset: 'USDC', amount: '500' });
255
+ ```
256
+
257
+ | Option | Type | Description |
258
+ | ----------- | ----------------- | -------------------------------------------------------------------- |
259
+ | `direction` | `'buy' \| 'sell'` | Buy (on-ramp) or sell (off-ramp). Defaults to `'buy'` |
260
+ | `country` | `string` | ISO 3166-1 alpha-2, e.g. `'BR'` |
261
+ | `fiat` | `string` | Currency code, e.g. `'BRL'`. Defaults to the country's first fiat |
262
+ | `asset` | `string` | Asset code, e.g. `'USDC'`. Defaults to the first asset for that fiat |
263
+ | `amount` | `string` | A plain decimal, e.g. `'100'` or `'12.5'`; anything else is left out |
264
+
265
+ A country that does not route in the requested direction, or that the app does not offer, opens on the widget's default
266
+ country, without the fiat, asset or amount; a fiat or asset the country does not offer opens on the country's first one.
267
+ Nothing is thrown. The options wait for the routes when they are still loading. Each call starts over: opening again
268
+ with other options, or with none, drops the earlier ones. `<RampWidget initial={options}>` takes the same options.
269
+
270
+ #### Modal options
271
+
272
+ The other `open*Modal` actions take options the same way: the modal opens on them and the user can still change each
273
+ one. An option the app or wallet cannot use (a network the app does not offer, an asset the wallet does not hold, a
274
+ provider that is not enabled, an amount that is not a plain decimal) is left out and that field opens on its default;
275
+ nothing is thrown. An option whose data is still loading is applied when it arrives. Each call starts over: opening
276
+ again with other options, or with none, drops the earlier ones. Every type is exported from `@pollar/react`, and each
277
+ modal takes the same options as its `initial` prop.
278
+
279
+ ```ts
280
+ openSendModal({ asset: 'USDC', destination: 'G...', amount: '25', memo: 'order-1042', onSuccess: ({ hash }) => save(hash) });
281
+ openSwapModal({ sell: 'XLM', buy: 'USDC', amount: '100' });
282
+ openEarnModal({ provider: 'blend', tab: 'withdraw' });
283
+ openReceiveModal({ chain: 'SOLANA' });
284
+ openCardModal({ panel: 'fund', amount: '50', onFunded: (funding) => track(funding.id) });
285
+ ```
286
+
287
+ | Action | Options |
288
+ | -------------------- | ------------------------------------------------------------------------------------------------------------------------ |
289
+ | `openSendModal` | `chain`, `asset` (code), `destination`, `amount`, `memo`, `memoType` (`'text' \| 'id' \| 'hash'`), `onSuccess({ hash })` |
290
+ | `openSwapModal` | `chain` (`'STELLAR' \| 'SOLANA'`), `sell` (code), `buy` (code), `amount`, `onSuccess({ hash })` |
291
+ | `openEarnModal` | `provider`, `opportunityId`, `tab` (`'deposit' \| 'withdraw'`), `amount`, `onSuccess({ hash })` |
292
+ | `openReceiveModal` | `chain` |
293
+ | `openTxHistoryModal` | `chain` |
294
+ | `openCardModal` | `panel: 'fund'` (opens the funding panel once the user's card loads), `amount`, `chain`, `onFunded(funding)` |
295
+
296
+ `onSuccess` is called once per transaction that lands while the modal is open; `onFunded` with each funding the user
297
+ sends from the card modal. A Solana or Polygon send takes `amount` in the asset's decimals, as the form shows it.
298
+
240
299
  #### Login options
241
300
 
242
301
  ```ts
@@ -314,13 +373,23 @@ session still carries it.
314
373
  ### Language
315
374
 
316
375
  Every modal, shared block (footer, copy button, amount field, pickers) and exported template speaks English (`en`),
317
- Spanish (`es`) and Portuguese (`pt`). The provider picks the language once, in this order:
376
+ Spanish (`es`) and Portuguese (`pt`). The language is, in this order:
318
377
 
319
378
  1. The language the app pins in the dashboard (Branding > Language, served as `styles.language`).
320
379
  2. The `language` prop of `<RampWidget>`, `<KycModal>`, `<RequirementFormModal>`, `<RegistryCheckModal>` or
321
380
  `<ProviderRegistrationModal>`, a BCP 47 tag.
322
- 3. The client's `locale` (`client={{ apiKey, locale: 'pt-BR' }}`), any BCP 47 tag.
323
- 4. The browser language.
381
+ 3. The `language` prop of `<PollarProvider>`, a BCP 47 tag.
382
+ 4. The client's `locale` (`client={{ apiKey, locale: 'pt-BR' }}`, or `client.setLocale(tag)` later), any BCP 47 tag.
383
+ 5. The browser language.
384
+
385
+ An app whose language changes at runtime passes it to the provider, and every open or later modal follows it without
386
+ remounting anything:
387
+
388
+ ```tsx
389
+ <PollarProvider client={{ apiKey }} language={i18n.language}>
390
+ ```
391
+
392
+ `getClient().setLocale(tag)` does the same from outside React; `config.locale` is the starting value.
324
393
 
325
394
  A tag the modals have no translation for is skipped, and English is the fallback. Every exported template takes a
326
395
  `language` prop (`PollarLanguage` from `@pollar/core`: `'en' | 'es' | 'pt'`); a template rendered inside the provider
package/dist/index.css CHANGED
@@ -3140,6 +3140,131 @@
3140
3140
  }
3141
3141
  }
3142
3142
 
3143
+ /* src/components/bridge-modal/BridgeModal.css */
3144
+ .pollar-bridge-form,
3145
+ .pollar-bridge-transfer {
3146
+ display: flex;
3147
+ flex-direction: column;
3148
+ gap: 0.875rem;
3149
+ }
3150
+ .pollar-bridge-chains {
3151
+ display: flex;
3152
+ align-items: flex-end;
3153
+ gap: 0.5rem;
3154
+ }
3155
+ .pollar-bridge-chains .pollar-bridge-field {
3156
+ flex: 1;
3157
+ min-width: 0;
3158
+ }
3159
+ .pollar-bridge-arrow {
3160
+ padding-bottom: 0.7rem;
3161
+ color: var(--pollar-muted, #6b7280);
3162
+ }
3163
+ .pollar-bridge-field {
3164
+ display: flex;
3165
+ flex-direction: column;
3166
+ gap: 0.375rem;
3167
+ }
3168
+ .pollar-bridge-label,
3169
+ .pollar-bridge-balance {
3170
+ font-size: 0.8125rem;
3171
+ color: var(--pollar-muted, #6b7280);
3172
+ }
3173
+ .pollar-bridge-label-row {
3174
+ display: flex;
3175
+ align-items: center;
3176
+ justify-content: space-between;
3177
+ gap: 0.5rem;
3178
+ }
3179
+ .pollar-bridge-balance {
3180
+ display: inline-flex;
3181
+ align-items: center;
3182
+ gap: 0.375rem;
3183
+ }
3184
+ .pollar-bridge-max {
3185
+ border: 0;
3186
+ background: none;
3187
+ padding: 0;
3188
+ font-size: 0.8125rem;
3189
+ font-weight: 600;
3190
+ color: var(--pollar-accent, #2563eb);
3191
+ cursor: pointer;
3192
+ }
3193
+ .pollar-bridge-quote {
3194
+ display: flex;
3195
+ flex-direction: column;
3196
+ gap: 0.375rem;
3197
+ margin: 0;
3198
+ padding: 0.75rem;
3199
+ border-radius: var(--pollar-input-border-radius, 0.5rem);
3200
+ background-color: var(--pollar-input-bg);
3201
+ }
3202
+ .pollar-bridge-quote > div {
3203
+ display: flex;
3204
+ justify-content: space-between;
3205
+ gap: 0.5rem;
3206
+ font-size: 0.875rem;
3207
+ }
3208
+ .pollar-bridge-quote dt {
3209
+ color: var(--pollar-muted, #6b7280);
3210
+ }
3211
+ .pollar-bridge-quote dd {
3212
+ margin: 0;
3213
+ font-weight: 600;
3214
+ text-align: right;
3215
+ }
3216
+ .pollar-bridge-note {
3217
+ margin: 0;
3218
+ font-size: 0.8125rem;
3219
+ color: var(--pollar-muted, #6b7280);
3220
+ }
3221
+ .pollar-bridge-status strong {
3222
+ display: block;
3223
+ font-size: 1rem;
3224
+ }
3225
+ .pollar-bridge-status p {
3226
+ margin: 0.25rem 0 0;
3227
+ font-size: 0.875rem;
3228
+ color: var(--pollar-muted, #6b7280);
3229
+ }
3230
+ .pollar-bridge-steps {
3231
+ display: flex;
3232
+ flex-direction: column;
3233
+ gap: 0.5rem;
3234
+ margin: 0;
3235
+ padding: 0;
3236
+ list-style: none;
3237
+ font-size: 0.875rem;
3238
+ }
3239
+ .pollar-bridge-step {
3240
+ display: flex;
3241
+ align-items: center;
3242
+ gap: 0.5rem;
3243
+ color: var(--pollar-muted, #6b7280);
3244
+ }
3245
+ .pollar-bridge-step-done {
3246
+ color: inherit;
3247
+ }
3248
+ .pollar-bridge-step-dot {
3249
+ width: 0.625rem;
3250
+ height: 0.625rem;
3251
+ border-radius: 999px;
3252
+ border: 2px solid currentColor;
3253
+ }
3254
+ .pollar-bridge-step-done .pollar-bridge-step-dot {
3255
+ background-color: var(--pollar-accent, #2563eb);
3256
+ border-color: var(--pollar-accent, #2563eb);
3257
+ }
3258
+ .pollar-bridge-links {
3259
+ display: flex;
3260
+ flex-wrap: wrap;
3261
+ gap: 0.75rem;
3262
+ font-size: 0.8125rem;
3263
+ }
3264
+ .pollar-bridge-links a {
3265
+ color: var(--pollar-accent, #2563eb);
3266
+ }
3267
+
3143
3268
  /* src/components/earn-modal/EarnModal.css */
3144
3269
  .pollar-earn-live {
3145
3270
  color: var(--pollar-accent);