|
| 1 | +import { |
| 2 | + useStore, |
| 3 | + useRef, |
| 4 | + onMount, |
| 5 | + onUnMount, |
| 6 | + Show, |
| 7 | +} from "@builder.io/mitosis"; |
| 8 | +import clx from "clsx"; |
| 9 | +import Box from "../box"; |
| 10 | +import Text from "../text"; |
| 11 | +import Tooltip from "../tooltip"; |
| 12 | +import Button from "../button"; |
| 13 | +import Icon from "../icon"; |
| 14 | +import * as styles from "./wallet-connector.css"; |
| 15 | + |
| 16 | +import { store } from "../../models/store"; |
| 17 | +import type { ThemeVariant } from "../../models/system.model"; |
| 18 | +import type { WalletConnectorStatusRingProps } from "./wallet-connector.types"; |
| 19 | + |
| 20 | +export default function WalletConnectorStatusRing( |
| 21 | + props: WalletConnectorStatusRingProps, |
| 22 | +) { |
| 23 | + const state = useStore<{ |
| 24 | + theme: ThemeVariant; |
| 25 | + }>({ |
| 26 | + theme: "light", |
| 27 | + }); |
| 28 | + |
| 29 | + let cleanupRef = useRef<() => void>(null); |
| 30 | + |
| 31 | + onMount(() => { |
| 32 | + state.theme = store.getState().theme; |
| 33 | + |
| 34 | + cleanupRef = store.subscribe((newState) => { |
| 35 | + state.theme = newState.theme; |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + onUnMount(() => { |
| 40 | + if (typeof cleanupRef === "function") cleanupRef(); |
| 41 | + }); |
| 42 | + |
| 43 | + return ( |
| 44 | + <Box |
| 45 | + display="flex" |
| 46 | + justifyContent="space-between" |
| 47 | + alignItems="center" |
| 48 | + className={clx( |
| 49 | + props.className, |
| 50 | + "wallet-connector-status-ring", |
| 51 | + styles.walletConnectorStatusRing, |
| 52 | + )} |
| 53 | + attributes={{ |
| 54 | + ...props.attributes, |
| 55 | + "data-status": props.status, |
| 56 | + }} |
| 57 | + > |
| 58 | + <img |
| 59 | + src={props.wallet.logo} |
| 60 | + alt={props.wallet.name} |
| 61 | + className={styles.walletConnectorStatusRingImg} |
| 62 | + /> |
| 63 | + |
| 64 | + <div |
| 65 | + className={styles.walletConnectorStatusRingActionPseudo} |
| 66 | + aria-hidden="true" |
| 67 | + data-status={props.status} |
| 68 | + /> |
| 69 | + |
| 70 | + <div |
| 71 | + className={styles.walletConnectorStatusRingAction} |
| 72 | + data-status={props.status} |
| 73 | + > |
| 74 | + <Show |
| 75 | + when={props.popoverAction} |
| 76 | + else={<Icon name="informationSimpleLine" color="inherit" />} |
| 77 | + > |
| 78 | + <Tooltip |
| 79 | + title={ |
| 80 | + <Text fontSize="$xs" color="$textSecondary" fontWeight="$medium"> |
| 81 | + {props.popoverAction.label} |
| 82 | + </Text> |
| 83 | + } |
| 84 | + > |
| 85 | + <Button |
| 86 | + onClick={() => props.popoverAction.onClick?.()} |
| 87 | + variant="unstyled" |
| 88 | + domAttributes={{ |
| 89 | + style: { |
| 90 | + color: "inherit", |
| 91 | + padding: "0", |
| 92 | + minWidth: "unset", |
| 93 | + }, |
| 94 | + }} |
| 95 | + > |
| 96 | + <Icon name="reload" color="inherit" /> |
| 97 | + </Button> |
| 98 | + </Tooltip> |
| 99 | + </Show> |
| 100 | + </div> |
| 101 | + </Box> |
| 102 | + ); |
| 103 | +} |
0 commit comments