Skip to content

Commit

Permalink
feat: crop EVM address on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Aug 8, 2024
1 parent 6307bab commit 5ef9893
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/ConnectMetamask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useGlobalContext } from "../context/Global";
import { EIP6963ProviderInfo, useWeb3Signer } from "../context/Web3";
import "../style/web3.scss";
import { formatError } from "../utils/errors";
import { cropString, isMobile } from "../utils/helper";

const connect = async (
notify: (type: string, message: string) => void,
Expand Down Expand Up @@ -122,13 +123,21 @@ const ShowAddress = ({
const { t } = useGlobalContext();
const { clearSigner } = useWeb3Signer();

const [text, setText] = createSignal<string>(address());
const formatAddress = (addr: string) => {
if (isMobile()) {
return cropString(addr);
}

return addr;
};

const [text, setText] = createSignal<string>(formatAddress(address()));

return (
<button
onClick={() => clearSigner()}
onMouseEnter={() => setText(t("disconnect_address"))}
onMouseLeave={() => setText(address())}
onMouseLeave={() => setText(formatAddress(address()))}
class="btn btn-light">
{text()}
</button>
Expand Down
1 change: 1 addition & 0 deletions src/context/Web3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const Web3SignerContext = createContext<{
// TODO: this is | undefined
signer: Accessor<Signer>;
clearSigner: () => void;

getEtherSwap: () => EtherSwap;
}>();

Expand Down

0 comments on commit 5ef9893

Please sign in to comment.