(
this,
TradeConfigCursor
);
// Watch for changes
connectedCallback() {
super.connectedCallback();
const watchId = 'my-watch-' + Math.random();
AccountCursor.addWatch(watchId, (_id, prev, curr) => {
if (prev?.address !== curr?.address) {
console.log('Account changed:', curr);
this.onAccountChange(prev, curr);
}
});
}
// Access state
render() {
const account = this.account.state;
const config = this.config.state;
return html`
Account: ${account?.address}
Slippage: ${config?.slippage}%
`;
}
}
// Update state globally
AccountCursor.reset({
address: '7L53bUTBbfuj14oDr6pMKvv72YwNUZJNjZPE3z5cpCPbqEDW',
provider: 'polkadot-js',
name: 'Alice'
});
TradeConfigCursor.reset({
slippage: '2',
slippageTwap: '5',
maxRetries: 3
});
```
--------------------------------
### Initiate Changeset for Releasing with npm
Source: https://github.com/galacticcouncil/apps/blob/master/CONTRIBUTING.md
Runs the changeset command to prepare for package releases. This step involves specifying new package versions and change summaries.
```sh
npm run changeset
```
--------------------------------
### BondsApp Component Integration and Event Listening (HTML, JavaScript)
Source: https://context7.com/galacticcouncil/apps/llms.txt
Sets up the BondsApp component for trading bonds, managing protocol-owned liquidity, and purchasing bonds. It listens for 'gc:tx:new' events to track bond purchase activities.
```html
```
--------------------------------
### Build Packages with npm
Source: https://github.com/galacticcouncil/apps/blob/master/CONTRIBUTING.md
Builds project packages using npm. This includes building distribution files with type definitions.
```sh
npm run build
```
--------------------------------
### Build and Watch Packages with npm
Source: https://github.com/galacticcouncil/apps/blob/master/CONTRIBUTING.md
Builds packages and enables watch mode for JavaScript files with hot reloading. This is useful for rapid development cycles.
```sh
npm run build:watch
```
--------------------------------
### YieldApp Component Integration and Event Listening (HTML, JavaScript)
Source: https://context7.com/galacticcouncil/apps/llms.txt
Integrates the YieldApp component for yield farming, liquidity provision, and reward claiming. Listens for 'gc:tx:new' events to log details about liquidity provision actions.
```html
```
--------------------------------
### Trade App Component Integration
Source: https://context7.com/galacticcouncil/apps/llms.txt
Integrates the `gc-trade` Web Component for spot trading. It supports automatic routing and TWAP orders. Configuration is done via HTML attributes, and events like new transactions and scheduled TWAP orders can be listened to.
```html
```
--------------------------------
### Execute Swap with Slippage Protection (TypeScript)
Source: https://context7.com/galacticcouncil/apps/llms.txt
Integrates the SDK to calculate and execute token swaps with built-in slippage protection. It calculates the best trade route, builds the transaction with specified slippage, performs a dry run, estimates fees, and sends the transaction. Dependencies include '@galacticcouncil/sdk' and a blockchain API provider.
```typescript
import { SdkCtx } from '@galacticcouncil/sdk';
async function executeSwap() {
const api = await ApiPromise.create({
provider: new WsProvider('wss://rpc.hydradx.cloud')
});
const sdk = await SdkCtx.create({ api });
// Calculate best sell route
const trade = await sdk.api.router.getBestSell(
'0', // HDX
'5', // DOT
'1000000000000' // 1 HDX (12 decimals)
);
console.log('Trade route:', trade.toHuman());
// Build transaction with slippage
const tx = await sdk.tx
.trade(trade)
.withSlippage(2) // 2% slippage
.withBeneficiary('7L53bUTBbfuj14oDr6pMKvv72YwNUZJNjZPE3z5cpCPbqEDW')
.build();
// Dry run to validate
const dryRun = await tx.dryRun('7L53bUTBbfuj14oDr6pMKvv72YwNUZJNjZPE3z5cpCPbqEDW');
console.log('Dry run result:', dryRun.executionResult.toHuman());
// Get payment info
const paymentInfo = await tx.paymentInfo('7L53bUTBbfuj14oDr6pMKvv72YwNUZJNjZPE3z5cpCPbqEDW');
console.log('Fee:', paymentInfo.partialFee.toString());
// Sign and send
const hash = await tx.signAndSend(signer);
console.log('Transaction hash:', hash);
}
```
--------------------------------
### Version, Lockfile, and Commit with Changeset
Source: https://github.com/galacticcouncil/apps/blob/master/CONTRIBUTING.md
Bumps package versions, updates the lockfile, and creates a commit message using the changeset tool. This prepares the project for publishing.
```sh
npm run changeset:version
```
--------------------------------
### Communicate with Custom Events (TypeScript)
Source: https://context7.com/galacticcouncil/apps/llms.txt
Explains how to use custom events for component communication with typed payloads. It covers dispatching and listening for transaction events, query parameter updates, and wallet change requests. Dependencies include custom interfaces like 'TxInfo'.
```typescript
// Transaction events
interface TxInfo {
account: Account;
transaction: SubstrateTransaction | Transaction;
notification: TxNotification;
meta?: T;
}
// Dispatch transaction
function dispatchSwapTx(
element: HTMLElement,
account: Account,
transaction: SubstrateTransaction,
meta: TradeMetadata
) {
const event = new CustomEvent('gc:tx:new', {
bubbles: true,
composed: true,
detail: {
account,
transaction,
notification: {
processing: { message: 'Swapping...', rawHtml: 'Swapping...' },
success: { message: 'Swap successful', rawHtml: 'Swap successful' },
failure: { message: 'Swap failed', rawHtml: 'Swap failed' }
},
meta
} as TxInfo
});
element.dispatchEvent(event);
}
// Listen for events
document.addEventListener('gc:tx:new', (e: CustomEvent) => {
const { account, transaction, notification, meta } = e.detail;
// Process transaction
submitTransaction(transaction, account);
});
// Query parameter updates
document.addEventListener('gc:query:update', (e: CustomEvent) => {
const { assetIn, assetOut } = e.detail;
console.log('URL params updated:', assetIn, assetOut);
});
// Wallet change requests
document.addEventListener('gc:wallet:change', (e: CustomEvent) => {
const { srcChain } = e.detail;
console.log('Wallet change requested for:', srcChain);
});
```
--------------------------------
### Schedule TWAP Order Configuration (TypeScript)
Source: https://context7.com/galacticcouncil/apps/llms.txt
Configures and schedules Time-Weighted Average Price (TWAP) orders using the SDK. It retrieves TWAP order parameters, builds the transaction with specified slippage and retries, calculates execution time, and submits the TWAP order. Dependencies include '@galacticcouncil/sdk'.
```typescript
async function scheduleTwapOrder() {
const sdk = await SdkCtx.create({ api });
// Get TWAP order parameters
const order = await sdk.api.scheduler.getTwapSellOrder(
'0', // HDX
'5', // DOT
'10000000000000', // 10 HDX total
);
console.log('Order details:', {
tradeCount: order.tradeCount,
tradeAmountIn: order.toHuman().tradeAmountIn,
frequency: order.frequency,
frequencyMin: order.frequencyMin,
frequencyOpt: order.frequencyOpt
});
// Build TWAP transaction
const tx = await sdk.tx
.order(order)
.withBeneficiary('7L53bUTBbfuj14oDr6pMKvv72YwNUZJNjZPE3z5cpCPbqEDW')
.withMaxRetries(3)
.withSlippage(5) // 5% slippage for TWAP
.build();
// Calculate duration
const duration = sdk.api.scheduler.getTwapExecutionTime(order.tradeCount);
console.log('Execution time:', duration, 'ms');
// Submit
const hash = await tx.signAndSend(signer);
console.log('TWAP scheduled:', hash);
}
```
--------------------------------
### Link Local Modules with npm
Source: https://github.com/galacticcouncil/apps/blob/master/CONTRIBUTING.md
Links local modules using npm. This command is typically used during local development to ensure that local packages are correctly linked.
```sh
npm run link
```
--------------------------------
### Load API Viewer Manifest Dynamically with JavaScript
Source: https://github.com/galacticcouncil/apps/blob/master/pages/api-viewer/public/index.html
This JavaScript code fetches the 'custom-elements.json' manifest and applies it to the 'api-viewer' component. It utilizes the EventSource API to reload the page upon changes detected by esbuild, ensuring the UI reflects the latest manifest data. No external libraries are required.
```javascript
new EventSource('/esbuild').addEventListener('change', () => location.reload());
fetch('./custom-elements.json')
.then((res) => res.json())
.then(({ schema, schemaVersion, modules }) => {
document.querySelector('api-viewer').manifest = {
schema: schema,
schemaVersion: schemaVersion,
modules: modules,
};
});
```
--------------------------------
### Use UIGC Alert Component (HTML)
Source: https://github.com/galacticcouncil/apps/blob/master/packages/ui/README.md
Demonstrates how to use the UIGC alert web component in HTML. The 'variant' attribute controls the appearance of the alert.
```html
```
--------------------------------
### Style API Viewer with CSS Themes
Source: https://github.com/galacticcouncil/apps/blob/master/pages/api-viewer/public/index.html
This CSS snippet defines theming for the API Viewer component based on HTML attributes. It sets primary colors for 'bsx' and 'hdx' themes, ensuring visual consistency. It also sets the maximum width for the viewer.
```css
html[theme='bsx'] api-viewer { --ave-primary-color: rgb(4, 176, 135); }
html[theme='hdx'] api-viewer { --ave-primary-color: #01579b; }
api-viewer { max-width: 100%; }
```
--------------------------------
### XCM App Component Integration
Source: https://context7.com/galacticcouncil/apps/llms.txt
Integrates the `gc-xcm` Web Component for cross-chain transfers across various blockchain ecosystems. It allows configuration of source and destination chains, assets, and account details. Event listeners handle transfer confirmations and wallet change requests, and the destination address can be set programmatically.
```html
```
--------------------------------
### Integrating XCM App via HTML Custom Element
Source: https://github.com/galacticcouncil/apps/blob/master/packages/apps/README.md
This snippet demonstrates the integration of the Xcm App using the `gc-xcm` custom element in HTML. It requires chain-related properties such as `chains`, `srcChain`, and `destChain`, along with optional account details like `accountAddress`, `accountProvider`, and `accountName`. The `asset` property specifies the asset for the cross-chain transaction.
```html
```
--------------------------------
### Dispatching New Transactions via JavaScript
Source: https://github.com/galacticcouncil/apps/blob/master/packages/apps/README.md
This code illustrates how to dispatch custom events for new on-chain or cross-chain transactions. It uses the `TxInfo` type for the message payload and dispatches events for 'gc:tx:new' (on-chain) and 'gc:xcm:new' (cross-chain). The `TxInfo` type includes details like the user's account, transaction specifics, notification metadata, and other transaction-related metadata.
```javascript
this.dispatchEvent(new CustomEvent() < TxInfo > ('gc:tx:new', message)); // on chain tx
this.dispatchEvent(new CustomEvent() < TxInfo > ('gc:xcm:new', message)); // cross chain tx
```
--------------------------------
### JavaScript for Live Reloading on File Changes
Source: https://github.com/galacticcouncil/apps/blob/master/pages/apps-web/public/index.html
Implements a JavaScript EventSource to listen for 'change' events from the '/esbuild' endpoint. Upon receiving a 'change' event, it triggers a page reload to reflect the latest updates, commonly used in development environments.
```javascript
new EventSource('/esbuild').addEventListener('change', () => location.reload());
```
--------------------------------
### DCA App Component Integration
Source: https://context7.com/galacticcouncil/apps/llms.txt
Integrates the `gc-dca` Web Component for Dollar Cost Averaging. This component enables automated recurring trades with customizable frequency and duration. It listens for schedule events and handles errors through notification events.
```html
```
--------------------------------
### Import UIGC Web Components (JavaScript)
Source: https://github.com/galacticcouncil/apps/blob/master/packages/ui/README.md
Imports the UIGC Web Components into your JavaScript application. This makes the custom elements available for use.
```js
import '@galacticcouncil/ui';
```
--------------------------------
### Xcm App Component
Source: https://github.com/galacticcouncil/apps/blob/master/packages/apps/README.md
Bare cross-chain transaction app component for XCM transfers without integrated tx and notification centers.
```APIDOC
## Xcm App Component
### Description
Bare cross chain transaction app without tx & notification center. Use this component for direct XCM transfers.
### Method
Custom Element
### Endpoint
``
### Parameters
#### Properties
- **accountAddress** (string) - account address. Optional.
- **accountProvider** (string) - account provider. Optional.
- **accountName** (string) - account name. Optional.
- **chains** (string) - listed chains. Required.
- **srcChain** (string) - source chain. Required.
- **destChain** (string) - destination chain. Required.
- **asset** (string) - asset to transfer. Required.
### Request Example
```html
```
### Response
N/A (This is a UI component)
```
--------------------------------
### Trade App Component
Source: https://github.com/galacticcouncil/apps/blob/master/packages/apps/README.md
Bare trade app component for performing trades without integrated tx and notification centers.
```APIDOC
## Trade App Component
### Description
Bare trade app without tx & notification center. Use this component for direct trade interactions.
### Method
Custom Element
### Endpoint
``
### Parameters
#### Properties
- **apiAddress** (string) - chain ws address. Required.
- **stableCoinAssetId** (string) - stablecoin id. Required.
- **accountAddress** (string) - account address. Optional.
- **accountProvider** (string) - account provider. Optional.
- **accountName** (string) - account name. Optional.
- **pools** (string) - list of pools. Optional.
- **assetIn** (string) - asset in id. Optional.
- **assetOut** (string) - asset out id. Optional.
### Request Example
```html
```
### Response
N/A (This is a UI component)
```
--------------------------------
### Main Content Area Styling for Galactic Apps
Source: https://github.com/galacticcouncil/apps/blob/master/pages/apps-web/public/index.html
Styles the main content area, adjusting margins based on the toolbar height and defining padding and height for the '#app' div within 'main' based on screen size using media queries.
```css
main {
width: 100%;
margin-top: var(--toolbar-height);
min-height: calc(100vh - var(--toolbar-height));
}
@media (min-width: 768px) {
main > div#app {
padding: 44px 0px;
}
}
@media (max-width: 480px) {
main > div#app {
height: 100%;
}
}
```
--------------------------------
### Dispatching New Notifications via JavaScript
Source: https://github.com/galacticcouncil/apps/blob/master/packages/apps/README.md
This snippet demonstrates how to dispatch a custom event to notify the Notification Center about a new notification. It requires a `Notification` type for the message payload and specifies that the event should be displayed as a toast. The `id`, `timestamp`, `message`, `type`, and `toast` attributes are crucial for proper notification handling.
```javascript
this.dispatchEvent(
new CustomEvent() < Notification > ('gc:notification:new', message)
);
```
--------------------------------
### Header and Navigation Styling for Galactic Apps
Source: https://github.com/galacticcouncil/apps/blob/master/pages/apps-web/public/index.html
Styles the header for fixed positioning and backdrop filter effects, adapting background colors based on themes ('bsx', 'hdx'). It also styles navigation links and their text, including hover effects and theme-specific font properties.
```css
body {
margin: 0;
}
header {
position: fixed;
top: 0px;
left: 0px;
z-index: 5;
height: var(--toolbar-height);
width: 100%;
backdrop-filter: blur(16px);
background: rgba(0, 0, 0, 0.2);
-webkit-box-align: center;
align-items: center;
display: flex;
flex-direction: row;
justify-content: center;
}
html[theme='bsx'] header {
background: rgba(28, 26, 31, 0.2);
}
html[theme='hdx'] header {
background: rgba(0, 0, 0, 0.2);
}
nav a {
text-decoration: none;
}
nav a span {
font-family: var(--uigc-app-font);
font-size: 16px;
line-height: 18px;
margin-right: 32px;
}
html nav a span:hover {
color: rgb(255, 255, 255);
}
html[theme='bsx'] nav span {
font-family: var(--uigc-app-font);
font-weight: 600;
color: rgb(158, 169, 177);
}
html[theme='hdx'] nav span {
font-family: var(--uigc-app-font);
text-transform: uppercase;
color: rgb(189, 204, 212);
}
```
--------------------------------
### Notification Center API
Source: https://github.com/galacticcouncil/apps/blob/master/packages/apps/README.md
API for the Notification Center component, used to display app notifications and history.
```APIDOC
## Notification Center API
### Description
Display app notifications (toast) and related history (drawer) based on slotted component event.
### Method
`dispatchEvent`
### Endpoint
`gc:notification:new`
### Parameters
#### Event Payload
- **message** (Notification) - The notification object to be dispatched.
### Request Example
```javascript
this.dispatchEvent(
new CustomEvent('gc:notification:new', message)
);
```
### Response
N/A (This is an event-driven API)
### Types
#### Notification Type
- **id** (string) - unique notification id
- **timestamp** (number) - unix timestamp
- **message** (string | HTMLElement) - string or html template
- **type** (string) - notification type
- **toast** (boolean) - whether to display toast
```
--------------------------------
### Global CSS Variables and Scrollbar Styling for Galactic Apps
Source: https://github.com/galacticcouncil/apps/blob/master/pages/apps-web/public/index.html
Defines global CSS variables for toolbar and footer heights, and customizes the appearance of scrollbars for vertical and horizontal scrolling. It also sets a default background for HTML elements and specific background properties for the 'hdx' theme.
```css
:root {
--toolbar-height: 65px;
--footer-height: 60px;
}
::-webkit-scrollbar {
width: 6px;
height: 6px;
}
::-webkit-scrollbar:horizontal {
width: 0px;
height: 0px;
}
::-webkit-scrollbar-thumb:vertical {
background: #676c80;
border-radius: 4px;
}
::-webkit-scrollbar-track {
background: rgb(28, 32, 56);
border-radius: 3px;
}
::-webkit-scrollbar-corner {
background: transparent;
}
html {
background: var(--uigc-app-background);
}
html[theme='hdx'] {
height: 474px;
background-repeat: no-repeat;
background-color: var(--uigc-app-background-color);
}
```
--------------------------------
### Transaction Center API
Source: https://github.com/galacticcouncil/apps/blob/master/packages/apps/README.md
API for the Transaction Center component, handling transaction processing and status display.
```APIDOC
## Transaction Center API
### Description
Process transaction & display status based on slotted component event. Dispatch result to Notification center.
### Method
`dispatchEvent`
### Endpoint
`gc:tx:new` (on chain tx), `gc:xcm:new` (cross chain tx)
### Parameters
#### Event Payload
- **message** (TxInfo) - The transaction information object to be dispatched.
### Request Example
```javascript
// On chain transaction
this.dispatchEvent(new CustomEvent('gc:tx:new', message));
// Cross chain transaction
this.dispatchEvent(new CustomEvent('gc:xcm:new', message));
```
### Response
N/A (This is an event-driven API)
### Types
#### TxInfo Type
- **account** (string) - User account (wallet)
- **transaction** (object) - Transaction info (extrinsic, hex)
- **notification** (object) - Notification center metadata
- **meta** (object) - Transaction metadata
```
--------------------------------
### HTML: Define Font Face with uigc-font-face
Source: https://github.com/galacticcouncil/apps/blob/master/packages/ui/doc/font.md
This HTML snippet demonstrates how to define a custom font using the `@font-face` CSS rule within a `
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.