Skip to content

Commit

Permalink
feat: added loading logic to multi-transaction modal
Browse files Browse the repository at this point in the history
  • Loading branch information
milorue committed Apr 13, 2022
1 parent 0264ac5 commit 26a5080
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/common/components/elements/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type ModalProps = {

export const Modal: FC<ModalProps> = ({ open, setOpen, children, title, priority = false }) => {
const modalRef = useRef<HTMLDivElement>(null!);
useOutsideAlerter(modalRef, () => setOpen(false));
useOutsideAlerter(modalRef, () => setOpen(priority)); // disable outside alerter if priority (require clicking close)

if (!open) {
return null;
Expand Down
8 changes: 5 additions & 3 deletions src/common/context/MultiTransaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export const MultiTransactionProvider: FC = ({ children }) => {
setActions(filtered);
}
setHasRemainingActions(false);
setHasRemainingActions(false);
} catch (err: any) {
const errorMsg: string = err.message;
if (errorMsg.includes(`User rejected the request`)) {
Expand Down Expand Up @@ -115,6 +114,7 @@ export const MultiTransactionProvider: FC = ({ children }) => {
setHasActionPending(true);
let filtered = newActionsWithIds;
for (const action of newActionsWithIds) {
setMessage(action.name);
await action.action(action.param);
settings?.onActionSuccess?.(action.id);
// clear action
Expand All @@ -140,7 +140,9 @@ export const MultiTransactionProvider: FC = ({ children }) => {

const completedActions = numActions - actions.length;
const percentage =
completedActions > 0 && numActions > 0 ? (completedActions / numActions) * 100 : 0;
numActions > 0 && completedActions < numActions
? ((completedActions + 1) / numActions) * 100
: 0;

return (
<MultiTransactionContext.Provider
Expand Down Expand Up @@ -169,7 +171,7 @@ export const MultiTransactionProvider: FC = ({ children }) => {
style={{ width: `${percentage}%` }}
>
<div
className={`relative flex h-full animate-loading rounded-full bg-gray-300`}
className={`relative flex h-full w-full animate-loading rounded-full bg-gray-300`}
></div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = {
},
keyframes: {
loadingbar: {
'0%': { left: 0, width: 0 },
'0%': { left: 0, width: 0, opacity: 0.5 },
'50%': { left: 0, width: '100%' },
'100%': { left: '100%', width: 0 },
},
Expand Down

0 comments on commit 26a5080

Please sign in to comment.