-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from alleslabs/feat/clear-admin
feat: add clear admin menuitem
- Loading branch information
Showing
22 changed files
with
652 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Icon } from "@chakra-ui/react"; | ||
import type { | ||
SigningCosmWasmClient, | ||
ChangeAdminResult, | ||
} from "@cosmjs/cosmwasm-stargate"; | ||
import type { StdFee } from "@cosmjs/stargate"; | ||
import { pipe } from "@rx-stream/pipe"; | ||
import { MdCheckCircle } from "react-icons/md"; | ||
import type { Observable } from "rxjs"; | ||
|
||
import { ExplorerLink } from "lib/components/ExplorerLink"; | ||
import { TxStreamPhase } from "lib/types"; | ||
import type { TxResultRendering, ContractAddr } from "lib/types"; | ||
import { formatUFee } from "lib/utils"; | ||
|
||
import { catchTxError } from "./common/catchTxError"; | ||
import { postTx } from "./common/post"; | ||
import { sendingTx } from "./common/sending"; | ||
|
||
interface ClearAdminTxParams { | ||
address: string; | ||
contractAddress: ContractAddr; | ||
fee: StdFee; | ||
memo?: string; | ||
client: SigningCosmWasmClient; | ||
onTxSucceed?: (txHash: string) => void; | ||
} | ||
|
||
export const clearAdminTx = ({ | ||
address, | ||
contractAddress, | ||
fee, | ||
memo, | ||
client, | ||
onTxSucceed, | ||
}: ClearAdminTxParams): Observable<TxResultRendering> => { | ||
return pipe( | ||
sendingTx(fee), | ||
postTx<ChangeAdminResult>({ | ||
postFn: () => client.clearAdmin(address, contractAddress, fee, memo), | ||
}), | ||
({ value: txInfo }) => { | ||
onTxSucceed?.(txInfo.transactionHash); | ||
return { | ||
value: null, | ||
phase: TxStreamPhase.SUCCEED, | ||
receipts: [ | ||
{ | ||
title: "Tx Hash", | ||
value: txInfo.transactionHash, | ||
html: ( | ||
<ExplorerLink type="tx_hash" value={txInfo.transactionHash} /> | ||
), | ||
}, | ||
{ | ||
title: "Tx Fee", | ||
value: `${formatUFee( | ||
txInfo.events.find((e) => e.type === "tx")?.attributes[0].value ?? | ||
"0u" | ||
)}`, | ||
}, | ||
], | ||
receiptInfo: { | ||
header: "Transaction Complete", | ||
headerIcon: ( | ||
<Icon as={MdCheckCircle} color="success.main" boxSize={6} /> | ||
), | ||
}, | ||
} as TxResultRendering; | ||
} | ||
)().pipe(catchTxError()); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useWallet } from "@cosmos-kit/react"; | ||
import { useCallback } from "react"; | ||
|
||
import { useFabricateFee } from "../hooks"; | ||
import { clearAdminTx } from "lib/app-fns/tx/clearAdmin"; | ||
import { CLEAR_ADMIN_GAS } from "lib/data"; | ||
import type { ContractAddr } from "lib/types"; | ||
|
||
export interface ClearAdminStreamParams { | ||
onTxSucceed?: (txHash: string) => void; | ||
} | ||
|
||
export const useClearAdminTx = (contractAddress: ContractAddr) => { | ||
const { address, getCosmWasmClient } = useWallet(); | ||
const fabricateFee = useFabricateFee(); | ||
const clearAdminFee = fabricateFee(CLEAR_ADMIN_GAS); | ||
|
||
return useCallback( | ||
async ({ onTxSucceed }: ClearAdminStreamParams) => { | ||
const client = await getCosmWasmClient(); | ||
if (!address || !client) | ||
throw new Error("Please check your wallet connection."); | ||
|
||
return clearAdminTx({ | ||
address, | ||
contractAddress, | ||
fee: clearAdminFee, | ||
client, | ||
onTxSucceed, | ||
}); | ||
}, | ||
[address, clearAdminFee, contractAddress, getCosmWasmClient] | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
export * from "./upload"; | ||
export * from "./resend"; | ||
export * from "./clearAdmin"; | ||
export * from "./execute"; | ||
export * from "./instantiate"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { | ||
Button, | ||
chakra, | ||
Icon, | ||
Menu, | ||
MenuButton, | ||
MenuItem, | ||
MenuList, | ||
Tooltip, | ||
} from "@chakra-ui/react"; | ||
import { useWallet } from "@cosmos-kit/react"; | ||
import { | ||
MdKeyboardArrowDown, | ||
MdPerson, | ||
MdPersonRemove, | ||
MdReadMore, | ||
} from "react-icons/md"; | ||
|
||
import { ClearAdminContract } from "../modal/contract/ClearAdminContract"; | ||
import { useInternalNavigate } from "lib/app-provider"; | ||
import type { ContractAddr, HumanAddr, Option } from "lib/types"; | ||
|
||
const StyledMenuItem = chakra(MenuItem, { | ||
baseStyle: { | ||
fontSize: "14px", | ||
}, | ||
}); | ||
|
||
const StyledIcon = chakra(Icon, { | ||
baseStyle: { | ||
boxSize: "4", | ||
display: "flex", | ||
alignItems: "center", | ||
}, | ||
}); | ||
|
||
interface AdminButtonProps { | ||
contractAddress: ContractAddr; | ||
admin: Option<HumanAddr | ContractAddr>; | ||
} | ||
|
||
export const AdminButton = ({ contractAddress, admin }: AdminButtonProps) => { | ||
const { address } = useWallet(); | ||
const navigate = useInternalNavigate(); | ||
|
||
const isAdmin = !!address && address === admin; | ||
return ( | ||
<Menu> | ||
<Tooltip | ||
hasArrow | ||
label="You don't have admin access to this contract." | ||
placement="top" | ||
bg="primary.dark" | ||
arrowSize={8} | ||
isDisabled={isAdmin} | ||
> | ||
<MenuButton | ||
variant="outline-gray" | ||
as={Button} | ||
isDisabled={!isAdmin} | ||
rightIcon={<Icon as={MdKeyboardArrowDown} boxSize="18px" />} | ||
> | ||
Admin | ||
</MenuButton> | ||
</Tooltip> | ||
<MenuList> | ||
<StyledMenuItem | ||
icon={<StyledIcon as={MdReadMore} color="gray.600" />} | ||
onClick={() => { | ||
navigate({ | ||
pathname: "/migrate", | ||
query: { contract: contractAddress }, | ||
}); | ||
}} | ||
> | ||
Migrate | ||
</StyledMenuItem> | ||
<StyledMenuItem | ||
icon={<StyledIcon as={MdPerson} color="gray.600" />} | ||
onClick={() => { | ||
navigate({ | ||
pathname: "/admin", | ||
query: { contract: contractAddress }, | ||
}); | ||
}} | ||
> | ||
Update Admin | ||
</StyledMenuItem> | ||
<ClearAdminContract | ||
contractAddress={contractAddress} | ||
triggerElement={ | ||
<StyledMenuItem | ||
icon={<StyledIcon as={MdPersonRemove} color="gray.600" />} | ||
> | ||
Clear Admin | ||
</StyledMenuItem> | ||
} | ||
/> | ||
</MenuList> | ||
</Menu> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from "./BackButton"; | ||
export * from "./ConnectWallet"; | ||
export * from "./InstantiateButton"; | ||
export * from "./ShowMoreButton"; | ||
export * from "./AdminButton"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Text } from "@chakra-ui/react"; | ||
import { useCallback } from "react"; | ||
import { MdDeleteForever } from "react-icons/md"; | ||
|
||
import { ActionModal } from "../ActionModal"; | ||
import { useClearAdminTx } from "lib/app-provider"; | ||
import { useTxBroadcast } from "lib/providers/tx-broadcast"; | ||
import type { ContractAddr } from "lib/types"; | ||
|
||
interface ClearAdminContractProps { | ||
contractAddress: ContractAddr; | ||
triggerElement: JSX.Element; | ||
} | ||
|
||
export const ClearAdminContract = ({ | ||
contractAddress, | ||
triggerElement, | ||
}: ClearAdminContractProps) => { | ||
const { broadcast } = useTxBroadcast(); | ||
const clearAdminTx = useClearAdminTx(contractAddress); | ||
|
||
const proceed = useCallback(async () => { | ||
const stream = await clearAdminTx({ onTxSucceed: () => {} }); | ||
if (stream) broadcast(stream); | ||
}, [broadcast, clearAdminTx]); | ||
|
||
return ( | ||
<ActionModal | ||
title="You'll no longer have admin access" | ||
icon={MdDeleteForever} | ||
iconColor="error.light" | ||
trigger={triggerElement} | ||
mainBtnTitle="Yes, clear it" | ||
mainAction={proceed} | ||
mainVariant="error" | ||
otherBtnTitle="No, keep it" | ||
otherVariant="ghost-primary" | ||
> | ||
<Text> | ||
Clearing the admin is a permanent action. You'll not be able to | ||
reassign an admin and migrations will no longer be possible. | ||
</Text> | ||
</ActionModal> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
4a0fa0d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
terra-celatone-frontend-staging – ./
terra-celatone-frontend-staging.vercel.app
terra-celatone-frontend-staging-alles-labs.vercel.app
terra-staging.celat.one
terra-celatone-frontend-staging-git-develop-alles-labs.vercel.app
4a0fa0d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
osmosis-celatone-frontend-staging – ./
osmosis-celatone-frontend-staging-alles-labs.vercel.app
osmosis-staging.celat.one
osmosis-celatone-frontend-staging-git-develop-alles-labs.vercel.app
celatone-frontend-staging.vercel.app