Skip to content

Commit

Permalink
feat: web3js demo
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyu1225 committed Dec 6, 2023
1 parent 0db7fe7 commit 9b6ea76
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { FC, ReactNode } from 'react';
import { isEmpty } from '../utils';
interface ButtonWithResultProps {
action: () => void;
result?: any;
label: string;
resultIsJson?: boolean;
children?: ReactNode;
}

const ButtonWithResult: FC<ButtonWithResultProps> = ({
action,
result = '',
label,
resultIsJson = false,
children,
}) => {
function replacer(key: string, value: any) {
if (typeof value === 'bigint') {
return {
type: 'bigint',
value: value.toString(),
};
} else {
return value;
}
}
const resultString = (result: any) => JSON.stringify(result, replacer);

return (
<>
<div>
<button onClick={action}>
<span>{label}</span>
</button>
{children}
</div>
{!isEmpty(result) && (
<code>
{label}: {resultIsJson ? resultString(result) : result}
</code>
)}
</>
);
};

export default ButtonWithResult;

0 comments on commit 9b6ea76

Please sign in to comment.