-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/react-package
- Loading branch information
Showing
18 changed files
with
788 additions
and
377 deletions.
There are no files selected for viewing
This file contains 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 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,19 @@ | ||
import { html } from 'lit'; | ||
|
||
const chevronIcon = html`<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
> | ||
<path | ||
d="M18 9.59998L12 15.6L6 9.59998" | ||
stroke="#A1A1AA" | ||
stroke-width="1.67" | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
/> | ||
</svg> `; | ||
|
||
export default chevronIcon; |
This file contains 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 |
---|---|---|
@@ -1,9 +1,35 @@ | ||
export { default as switchNetworkIcon } from './icons/switchNetwork'; | ||
export { default as sygmaLogo } from './icons/sygmaLogo'; | ||
export { default as noNetworkIcon } from './icons/noNetworkIcon'; | ||
export { default as ethereumIcon } from './icons/ethereumNetworkIcon'; | ||
export { default as polygonNetworkIcon } from './icons/polygonNetworkIcon'; | ||
export { default as baseNetworkIcon } from './icons/baseNetworkIcon'; | ||
export { default as cronosNetworkIcon } from './icons/cronosNetworkIcon'; | ||
export { default as phalaNetworkIcon } from './icons/phalaNetworkIcon'; | ||
export { default as khalaNetworkIcon } from './icons/khalaNetworkIcon'; | ||
import type { HTMLTemplateResult } from 'lit'; | ||
import baseNetworkIcon from './icons/baseNetworkIcon'; | ||
import cronosNetworkIcon from './icons/cronosNetworkIcon'; | ||
import ethereumIcon from './icons/ethereumNetworkIcon'; | ||
import khalaNetworkIcon from './icons/khalaNetworkIcon'; | ||
import noNetworkIcon from './icons/noNetworkIcon'; | ||
import phalaNetworkIcon from './icons/phalaNetworkIcon'; | ||
import polygonNetworkIcon from './icons/polygonNetworkIcon'; | ||
import switchNetworkIcon from './icons/switchNetwork'; | ||
import sygmaLogo from './icons/sygmaLogo'; | ||
import chevronIcon from './icons/chevron'; | ||
|
||
export const networkIconsMap = { | ||
ethereum: ethereumIcon, | ||
khala: khalaNetworkIcon, | ||
phala: phalaNetworkIcon, | ||
cronos: cronosNetworkIcon, | ||
base: baseNetworkIcon, | ||
gnosis: noNetworkIcon, | ||
polygon: polygonNetworkIcon, | ||
default: noNetworkIcon | ||
} as const as Record<string, HTMLTemplateResult>; | ||
|
||
export { | ||
ethereumIcon, | ||
khalaNetworkIcon, | ||
phalaNetworkIcon, | ||
cronosNetworkIcon, | ||
baseNetworkIcon, | ||
polygonNetworkIcon, | ||
sygmaLogo, | ||
switchNetworkIcon, | ||
noNetworkIcon, | ||
chevronIcon | ||
}; |
80 changes: 80 additions & 0 deletions
80
packages/widget/src/components/address-input/address-input.ts
This file contains 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,80 @@ | ||
import { LitElement, html } from 'lit'; | ||
import type { HTMLTemplateResult } from 'lit'; | ||
import { customElement, property, state } from 'lit/decorators.js'; | ||
import { ifDefined } from 'lit/directives/if-defined.js'; | ||
import { Network } from '@buildwithsygma/sygma-sdk-core'; | ||
import { when } from 'lit/directives/when.js'; | ||
import { validateAddress } from '../../utils'; | ||
import { styles } from './styles'; | ||
|
||
@customElement('sygma-address-input') | ||
export class AddressInput extends LitElement { | ||
static styles = styles; | ||
@property({ | ||
type: String | ||
}) | ||
address: string = ''; | ||
|
||
@property({ attribute: false }) | ||
onAddressChange: (address: string) => void = () => {}; | ||
|
||
@property({ | ||
type: String | ||
}) | ||
network: Network = Network.EVM; | ||
|
||
@state() | ||
errorMessage: string | null = null; | ||
|
||
connectedCallback(): void { | ||
super.connectedCallback(); | ||
this.handleAddressChange(this.address); | ||
} | ||
|
||
private handleAddressChange = (value: string): void => { | ||
const trimedValue = value.trim(); | ||
|
||
if (this.errorMessage) { | ||
this.errorMessage = null; | ||
} | ||
|
||
if (!trimedValue) { | ||
return; | ||
} | ||
|
||
this.errorMessage = validateAddress(trimedValue, this.network); | ||
|
||
if (!this.errorMessage) { | ||
void this.onAddressChange(trimedValue); | ||
} | ||
}; | ||
|
||
render(): HTMLTemplateResult { | ||
return html` <section class="inputAddressSection"> | ||
<div class="inputAddressContainer"> | ||
<label class="labelContainer"> | ||
<span>Send to </span> | ||
${when( | ||
this.errorMessage, | ||
() => html` <span class="errorMessage">${this.errorMessage}</span>` | ||
)}</label | ||
> | ||
<textarea | ||
class=${this.errorMessage ? 'inputAddress error' : 'inputAddress'} | ||
name="address" | ||
@change=${(evt: Event) => | ||
this.handleAddressChange((evt.target as HTMLInputElement).value)} | ||
> | ||
${ifDefined(this.address)} | ||
</textarea | ||
> | ||
</div> | ||
</section>`; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'sygma-address-input': AddressInput; | ||
} | ||
} |
This file contains 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 @@ | ||
export { AddressInput } from './address-input'; |
This file contains 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,51 @@ | ||
import { css } from 'lit'; | ||
|
||
export const styles = css` | ||
.inputAddressSection { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
gap: 0.5rem; | ||
min-height: 7.75rem; // TOO: remove this hardcoded value | ||
} | ||
.inputAddressContainer { | ||
display: flex; | ||
flex-direction: column; | ||
width: 100%; | ||
min-height: 7.75rem; // TOO: remove this hardcoded value | ||
gap: 0.5rem; | ||
} | ||
.inputAddress { | ||
border-radius: 1.5rem; | ||
border: 0.063rem solid var(--zinc-200); | ||
font-size: 0.875rem; | ||
text-align: center; | ||
resize: none; | ||
box-sizing: border-box; | ||
overflow: hidden; | ||
padding: 1rem; | ||
} | ||
.inputAddress:focus { | ||
outline: none; | ||
border: 0.063rem solid var(--zinc-200); | ||
} | ||
.error { | ||
border-color: red; | ||
} | ||
.errorMessage { | ||
color: red; | ||
font-weight: 300; | ||
font-size: 0.75rem; | ||
} | ||
.labelContainer { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
} | ||
`; |
This file contains 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 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { AmountSelector } from './amount-selector'; | ||
export { NetworkSelector } from './network-selector'; | ||
export { AddressInput } from './address-input'; |
Oops, something went wrong.