Skip to content

Commit de5207a

Browse files
committed
feat(ui): implement multiple buttons support
1 parent a7a5e62 commit de5207a

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

packages/ui/src/app/App.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ const App: Component<AppProps> = props => {
3333
<ConnectorContext.Provider value={appState.connector}>
3434
<GlobalStyles />
3535
<ThemeProvider theme={themeState}>
36-
<Show when={appState.buttonRootId}>
37-
<Portal mount={document.getElementById(appState.buttonRootId!)!}>
38-
<AccountButton />
39-
</Portal>
36+
<Show when={Array.isArray(appState.buttonRootId) && appState.buttonRootId.length > 0}>
37+
<>
38+
{appState.buttonRootId && (appState.buttonRootId as string[]).map((id) => (
39+
<Portal mount={document.getElementById(id)!}>
40+
<AccountButton />
41+
</Portal>
42+
))}
43+
</>
4044
</Show>
4145
<Dynamic component={globalStylesTag}>
4246
<WalletsModal />

packages/ui/src/app/state/app.state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Loadable } from 'src/models/loadable';
77

88
export type AppState = {
99
connector: ITonConnect;
10-
buttonRootId: string | null;
10+
buttonRootId: string | null | string[];
1111
language: Locales;
1212
walletsListConfiguration: WalletsListConfiguration | {};
1313
connectRequestParameters?: Loadable<ConnectAdditionalRequest> | null;

packages/ui/src/models/ton-connect-ui-options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface TonConnectUiOptions {
1414
* HTML element id to attach the wallet connect button. If not passed button won't appear.
1515
* @default null.
1616
*/
17-
buttonRootId?: string | null;
17+
buttonRootId?: string | null | string[];
1818

1919
/**
2020
* Language for the phrases it the UI elements.

packages/ui/src/ton-connect-ui.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,11 +993,21 @@ export class TonConnectUI {
993993
return rootId;
994994
}
995995

996-
private checkButtonRootExist(buttonRootId: string | null | undefined): void | never {
996+
private checkButtonRootExist(buttonRootId: string | string[] | null | undefined): void | never {
997997
if (buttonRootId == null) {
998998
return;
999999
}
10001000

1001+
if (Array.isArray(buttonRootId)) {
1002+
for (const buttonId of buttonRootId) {
1003+
if (document.getElementById(buttonId)) {
1004+
return;
1005+
}
1006+
}
1007+
1008+
throw new TonConnectUIError(`${buttonRootId} element not found in the document.`);
1009+
}
1010+
10011011
if (!document.getElementById(buttonRootId)) {
10021012
throw new TonConnectUIError(`${buttonRootId} element not found in the document.`);
10031013
}

0 commit comments

Comments
 (0)