From c03ac19f74f7036f3c26203ee139564f6b5608b6 Mon Sep 17 00:00:00 2001 From: SwiftHawk Date: Mon, 20 May 2024 13:28:46 +0500 Subject: [PATCH] Chore: quick fix --- src/pages/create/index.tsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/pages/create/index.tsx b/src/pages/create/index.tsx index 619a9f0..56b07c0 100644 --- a/src/pages/create/index.tsx +++ b/src/pages/create/index.tsx @@ -89,13 +89,21 @@ export const CreatePage = () => { const addUser = (pubkey: string) => { setUsers((prev) => { + const signers = prev.filter((user) => user.role === UserRole.signer) + const viewers = prev.filter((user) => user.role === UserRole.viewer) + const existingUserIndex = prev.findIndex( (user) => user.pubkey === pubkey ) // add new - if (existingUserIndex === -1) - return [...prev, { pubkey, role: userRole }] + if (existingUserIndex === -1) { + if (userRole === UserRole.signer) { + return [...signers, { pubkey, role: userRole }, ...viewers] + } else { + return [...signers, ...viewers, { pubkey, role: userRole }] + } + } const existingUser = prev[existingUserIndex] @@ -108,7 +116,11 @@ export const CreatePage = () => { updatedUser.role = userRole updatedUsers[existingUserIndex] = updatedUser - return updatedUsers + // signers should be placed at the start of the array + return [ + ...updatedUsers.filter((user) => user.role === UserRole.signer), + ...updatedUsers.filter((user) => user.role === UserRole.viewer) + ] }) } @@ -527,6 +539,7 @@ const DisplayUser = ({ .filter((user) => user.role === UserRole.signer) .map((user, index) => (