-
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 #113 from alleslabs/page/update-admin
Page/update admin
- Loading branch information
Showing
17 changed files
with
404 additions
and
62 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
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,74 @@ | ||
import { Icon } from "@chakra-ui/react"; | ||
import type { | ||
ExecuteResult, | ||
SigningCosmWasmClient, | ||
} 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 type { ContractAddr, HumanAddr, TxResultRendering } from "lib/types"; | ||
import { TxStreamPhase } from "lib/types"; | ||
import { formatUFee } from "lib/utils"; | ||
|
||
import { catchTxError, postTx, sendingTx } from "./common"; | ||
|
||
interface UpdateAdminTxParams { | ||
address: HumanAddr; | ||
contractAddress: ContractAddr; | ||
newAdmin: HumanAddr | ContractAddr; | ||
fee: StdFee; | ||
client: SigningCosmWasmClient; | ||
onTxSucceed?: () => void; | ||
onTxFailed?: () => void; | ||
} | ||
|
||
export const updateAdminTx = ({ | ||
address, | ||
contractAddress, | ||
newAdmin, | ||
fee, | ||
client, | ||
onTxSucceed, | ||
onTxFailed, | ||
}: UpdateAdminTxParams): Observable<TxResultRendering> => { | ||
return pipe( | ||
sendingTx(fee), | ||
postTx<ExecuteResult>({ | ||
postFn: () => | ||
client.updateAdmin(address, contractAddress, newAdmin, fee, undefined), | ||
}), | ||
({ value: txInfo }) => { | ||
onTxSucceed?.(); | ||
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: "Update Admin Complete", | ||
headerIcon: ( | ||
<Icon as={MdCheckCircle} color="success.main" boxSize={6} /> | ||
), | ||
}, | ||
actionVariant: "update-admin", | ||
} as TxResultRendering; | ||
} | ||
)().pipe(catchTxError(onTxFailed)); | ||
}; |
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,5 +1,6 @@ | ||
export * from "./upload"; | ||
export * from "./resend"; | ||
export * from "./clearAdmin"; | ||
export * from "./execute"; | ||
export * from "./instantiate"; | ||
export * from "./resend"; | ||
export * from "./updateAdmin"; | ||
export * from "./clearAdmin"; |
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,44 @@ | ||
import type { StdFee } from "@cosmjs/stargate"; | ||
import { useWallet } from "@cosmos-kit/react"; | ||
import { useCallback } from "react"; | ||
|
||
import { updateAdminTx } from "lib/app-fns/tx/updateAdmin"; | ||
import type { ContractAddr, HumanAddr, Option } from "lib/types"; | ||
|
||
export interface UpdateAdminStreamParams { | ||
contractAddress: ContractAddr; | ||
newAdmin: HumanAddr | ContractAddr; | ||
estimatedFee: Option<StdFee>; | ||
onTxSucceed?: () => void; | ||
onTxFailed?: () => void; | ||
} | ||
|
||
export const useUpdateAdminTx = () => { | ||
const { address, getCosmWasmClient } = useWallet(); | ||
|
||
return useCallback( | ||
async ({ | ||
contractAddress, | ||
newAdmin, | ||
estimatedFee, | ||
onTxSucceed, | ||
onTxFailed, | ||
}: UpdateAdminStreamParams) => { | ||
const client = await getCosmWasmClient(); | ||
if (!address || !client) | ||
throw new Error("Please check your wallet connection."); | ||
if (!estimatedFee) return null; | ||
|
||
return updateAdminTx({ | ||
address: address as HumanAddr, | ||
contractAddress, | ||
newAdmin, | ||
fee: estimatedFee, | ||
client, | ||
onTxSucceed, | ||
onTxFailed, | ||
}); | ||
}, | ||
[address, 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { FlexProps } from "@chakra-ui/react"; | ||
import { Flex, Icon, Text } from "@chakra-ui/react"; | ||
import { IoIosWarning } from "react-icons/io"; | ||
|
||
interface ErrorMessageRenderProps extends FlexProps { | ||
error: string; | ||
} | ||
|
||
export const ErrorMessageRender = ({ | ||
error, | ||
...restProps | ||
}: ErrorMessageRenderProps) => { | ||
return ( | ||
<Flex gap={2} {...restProps}> | ||
<Icon as={IoIosWarning} boxSize={4} color="error.main" /> | ||
<Text variant="body3" color="error.main"> | ||
{error} | ||
</Text> | ||
</Flex> | ||
); | ||
}; |
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
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.
c4f6c8a
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
celatone-frontend-staging.vercel.app
osmosis-celatone-frontend-staging-git-develop-alles-labs.vercel.app
osmosis-staging.celat.one
c4f6c8a
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-git-develop-alles-labs.vercel.app
terra-celatone-frontend-staging-alles-labs.vercel.app
terra-celatone-frontend-staging.vercel.app
terra-staging.celat.one