Skip to content

Commit

Permalink
feat: adding properties to widget, some new interface
Browse files Browse the repository at this point in the history
  • Loading branch information
wainola committed Feb 5, 2024
1 parent 5dfde30 commit 13d1c6b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
8 changes: 5 additions & 3 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
"type": "module",
"dependencies": {
"@buildwithsygma/sygmaprotocol-widget": "workspace:*",
"@lit/react": "1.0.3"
},
"peerDependencies": {
"@lit/react": "1.0.3",
"react": ">=17",
"react-dom": ">=17"
},
"devDependencies": {
"@types/react": ">=17",
"typescript": "5.2.2"
},
"scripts": {
"build": "tsc --build --clean && tsc --build ./tsconfig.json",
"dev": "tsc --build --clean && tsc --build ./tsconfig.json --watch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { createComponent } from '@lit/react';
import { SygmaProtocolWidget } from '@buildwithsygma/sygmaprotocol-widget';

export const SygmaProtocolReactWidget = createComponent({
export const SygmaProtocolReactWidget = createComponent<SygmaProtocolWidget>({
tagName: 'sygmaprotocol-widget',
elementClass: SygmaProtocolWidget,
react: React
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { SygmaProtocolReactWidget } from './WidgetReact';
10 changes: 8 additions & 2 deletions packages/widget/src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type {
Network,
SubstrateResource
} from '@buildwithsygma/sygma-sdk-core';
import type { ethers } from 'ethers';
import type { ApiPromise } from '@polkadot/api';
import type { Signer } from '@polkadot/api/types';

Expand All @@ -16,10 +15,17 @@ export type ThemeVariables =

export type Theme = Record<ThemeVariables, string>;

export interface Eip1193Provider {
request(request: {
method: string;
params?: Array<unknown> | Record<string, unknown>;
}): Promise<unknown>;
}

export interface ISygmaProtocolWidget {
whitelistedSourceNetworks?: Network[];
whitelistedDestinationNetworks?: Network[];
evmProvider?: ethers.providers.Web3Provider;
evmProvider?: Eip1193Provider;
substrateProvider?: ApiPromise | string;
substrateSigner?: Signer;
show?: boolean;
Expand Down
42 changes: 39 additions & 3 deletions packages/widget/src/widget.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,54 @@
import type { HTMLTemplateResult } from 'lit';
import { LitElement, html } from 'lit';
import { customElement } from 'lit/decorators.js';
import { customElement, property } from 'lit/decorators.js';
import type {
EvmResource,
Network,
SubstrateResource
} from '@buildwithsygma/sygma-sdk-core';
import type { ApiPromise } from '@polkadot/api';
import type { Signer } from '@polkadot/api/types';
import { styles } from './styles';
import { switchNetworkIcon, sygmaLogo } from './assets';
import { WidgetController } from './controllers/widget';
import './components/network-selector';
import './components/amount-selector';
import './components/address-input';
import { Directions } from './components/network-selector/network-selector';
import type {
Eip1193Provider,
ISygmaProtocolWidget,
Theme
} from './interfaces';

@customElement('sygmaprotocol-widget')
class SygmaProtocolWidget extends LitElement {
class SygmaProtocolWidget extends LitElement implements ISygmaProtocolWidget {
static styles = styles;

@property({ type: Array }) whitelistedSourceNetworks?: Network[];

@property({ type: Array }) whitelistedDestinationNetworks?: Network[];

@property({ type: Object }) evmProvider?: Eip1193Provider;

@property() substrateProvider?: ApiPromise | string;

@property({ type: Object }) substrateSigner?: Signer;

@property({ type: Boolean }) show?: boolean;

@property({ type: Array }) whitelistedSourceResources?: Array<
EvmResource | SubstrateResource
>;

@property({ type: Boolean }) expandable?: boolean;

@property({ type: Boolean }) darkTheme?: boolean;

@property({ type: Object }) customLogo?: SVGElement;

@property({ type: Object }) theme?: Theme;

private widgetController = new WidgetController(this, {});

render(): HTMLTemplateResult {
Expand Down Expand Up @@ -81,6 +117,6 @@ export { SygmaProtocolWidget };

declare global {
interface HTMLElementTagNameMap {
'sygmaprotocol-widget': SygmaProtocolWidget;
'sygmaprotocol-widget': ISygmaProtocolWidget;
}
}

0 comments on commit 13d1c6b

Please sign in to comment.