Skip to content

Commit

Permalink
chore: refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
evilpeach committed Jul 18, 2023
1 parent 240a275 commit 438076f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/lib/app-provider/hooks/useExampleAddresses.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { toBech32 } from "@cosmjs/encoding";
import { useMemo } from "react";

import type { ContractAddr, HumanAddr, ValidatorAddr } from "lib/types";
import type { ContractAddr, HumanAddr } from "lib/types";
import { addrToValoper } from "lib/utils";

import { useCurrentChain } from "./useCurrentChain";
Expand All @@ -11,26 +11,27 @@ export const useExampleAddresses = () => {
chain: { bech32_prefix: prefix },
} = useCurrentChain();

return useMemo(() => {
const bytes = Array(32)
.fill(undefined)
.map((_, idx) => idx);

const generateExampleAddresses = () => {
const bytes = Array.from(Array(32).keys());
const user = toBech32(
prefix,
new Uint8Array(bytes.slice(0, 20))
) as HumanAddr;

// reverse the bytes so the initial characters are different from the user address
const contract = toBech32(
prefix,
new Uint8Array(bytes.reverse())
) as ContractAddr;
const validator = addrToValoper(user) as ValidatorAddr;

const validator = addrToValoper(user);

return {
user,
contract,
validator,
};
}, [prefix]);
};

return useMemo(generateExampleAddresses, [prefix]);
};

0 comments on commit 438076f

Please sign in to comment.