@broxus/tvm-connect
Version:
TypeScript SDK for connecting to Nekoton-compatible wallets using a unified interface.
58 lines (57 loc) • 3.7 kB
JavaScript
import { Icon } from '@broxus/react-components';
import { Button, Grid, Text } from '@broxus/react-uikit';
import classNames from 'classnames';
import { observer } from 'mobx-react-lite';
import * as React from 'react';
import { useIntl } from 'react-intl';
import { useSharedParams, useTvmConnectDialog } from '../context';
import messages from '../intl';
export const TvmConnectionRequest = observer(() => {
const intl = useIntl();
const params = useSharedParams();
const dialog = useTvmConnectDialog();
const provider = dialog.connectingProvider;
const providerInfo = provider?.connector?.info;
const universalLink = providerInfo?.links?.universalLink;
const tryAgain = async () => {
if (provider) {
dialog.setState('error', undefined);
await dialog.connectTo(provider);
}
};
const onBack = () => {
dialog.setState({
error: undefined,
requestState: (universalLink && (dialog.qrEnabled ?? params.qrEnabled ?? true)) ? 'mobile' : undefined,
});
if (!dialog.requestState) {
dialog.setData({
connectingProvider: undefined,
});
}
};
return (React.createElement(React.Fragment, null,
React.createElement(Button, { className: "tvm-connect-back-button uk-position-top-left", type: "text", onClick: onBack },
React.createElement(Icon, { icon: "arrowLeft", ratio: 0.9 })),
React.createElement("div", { className: "tvm-connect-provider-content uk-animation-fade", style: {
animationDelay: 'var(--animation-medium-fast-duration)',
animationDuration: 'var(--animation-fast-duration)',
animationTimingFunction: 'var(--ease-in)',
} },
React.createElement(Grid, { childWidth: 1, gap: "collapse" },
providerInfo?.icon && (React.createElement(Text, { align: "center", className: classNames('uk-margin-top', {
'uk-margin-bottom': providerInfo.description,
'uk-margin-medium-bottom': !providerInfo.description,
}), component: "div" },
React.createElement("img", { alt: providerInfo.name, height: 60, src: providerInfo.icon, width: 60 }))),
providerInfo?.description && (React.createElement(Text, { align: "center", className: "uk-margin-medium-bottom", component: "div", kind: "meta" }, providerInfo.description)),
!dialog.error ? (React.createElement("div", { className: "uk-text-center" },
React.createElement(Text, { className: "tvm-connect-provider-content-title", component: "h4" }, intl.formatMessage(messages.TVM_CONNECT_POPUP_REQUEST_TITLE, {
providerName: providerInfo?.name ?? 'wallet',
})),
React.createElement(Text, { className: "uk-margin-small-bottom", size: "small" }, intl.formatMessage(messages.TVM_CONNECT_POPUP_REQUEST_NOTE)))) : (React.createElement("div", { className: "uk-text-center" },
React.createElement(Text, { className: "tvm-connect-provider-content-title", component: "h4" }, intl.formatMessage(messages.TVM_CONNECT_POPUP_REQUEST_FAILED_TITLE)),
React.createElement(Text, { className: "uk-margin-small-bottom", color: "danger", component: "div", size: "small" }, dialog.error.message
?? intl.formatMessage(messages.TVM_CONNECT_POPUP_REQUEST_FAILED_NOTE)),
React.createElement(Button, { type: "link", onClick: tryAgain }, intl.formatMessage(messages.TVM_CONNECT_POPUP_REQUEST_TRY_AGAIN_BTN_TEXT))))))));
});