add execute message page (#694)
This commit is contained in:
parent
b7a0f8523b
commit
dfce8d6a12
@ -2,6 +2,7 @@ import { Navigate, Outlet, Route, Routes as RoutesWrapper } from 'react-router-d
|
|||||||
|
|
||||||
import Layout from 'pages/_layout'
|
import Layout from 'pages/_layout'
|
||||||
import BorrowPage from 'pages/BorrowPage'
|
import BorrowPage from 'pages/BorrowPage'
|
||||||
|
import ExecuteMessagePage from 'pages/ExecuteMessagePage'
|
||||||
import FarmPage from 'pages/FarmPage'
|
import FarmPage from 'pages/FarmPage'
|
||||||
import HLSFarmPage from 'pages/HLSFarmPage'
|
import HLSFarmPage from 'pages/HLSFarmPage'
|
||||||
import HLSStakingPage from 'pages/HLSStakingPage'
|
import HLSStakingPage from 'pages/HLSStakingPage'
|
||||||
@ -35,6 +36,7 @@ export default function Routes() {
|
|||||||
{ENABLE_HLS && <Route path='/hls-farm' element={<HLSFarmPage />} />}
|
{ENABLE_HLS && <Route path='/hls-farm' element={<HLSFarmPage />} />}
|
||||||
<Route path='/' element={<TradePage />} />
|
<Route path='/' element={<TradePage />} />
|
||||||
<Route path='/wallets/:address'>
|
<Route path='/wallets/:address'>
|
||||||
|
<Route path='execute' element={<ExecuteMessagePage />} />
|
||||||
<Route path='trade' element={<TradePage />} />
|
<Route path='trade' element={<TradePage />} />
|
||||||
<Route path='trade-advanced' element={<TradePage />} />
|
<Route path='trade-advanced' element={<TradePage />} />
|
||||||
{ENABLE_PERPS && <Route path='perps' element={<PerpsPage />} />}
|
{ENABLE_PERPS && <Route path='perps' element={<PerpsPage />} />}
|
||||||
|
93
src/pages/ExecuteMessagePage.tsx
Normal file
93
src/pages/ExecuteMessagePage.tsx
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
import { useState } from 'react'
|
||||||
|
import { useSearchParams } from 'react-router-dom'
|
||||||
|
|
||||||
|
import Text from 'components/Text'
|
||||||
|
import WarningMessages from 'components/WarningMessages'
|
||||||
|
import { ENV } from 'constants/env'
|
||||||
|
import useStore from 'store'
|
||||||
|
|
||||||
|
import ActionButton from '../components/Button/ActionButton'
|
||||||
|
|
||||||
|
export default function ExecuteMessagePage() {
|
||||||
|
const [searchParams] = useSearchParams()
|
||||||
|
|
||||||
|
const [contract, setContract] = useState<string>(
|
||||||
|
searchParams.get('contract') ?? ENV.ADDRESS_CREDIT_MANAGER,
|
||||||
|
)
|
||||||
|
const [message, setMessage] = useState<string>(atob(searchParams.get('msg') ?? ''))
|
||||||
|
const [funds, setFunds] = useState<string>(atob(searchParams.get('funds') ?? ''))
|
||||||
|
|
||||||
|
const [messageWarnings, setMessageWarnings] = useState<string[]>([])
|
||||||
|
const [fundsWarnings, setFundsWarnings] = useState<string[]>([])
|
||||||
|
|
||||||
|
const execute = useStore((s) => s.execute)
|
||||||
|
|
||||||
|
function onChangeTextArea(value: string) {
|
||||||
|
setMessage(value)
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (value !== '') JSON.parse(value)
|
||||||
|
setMessageWarnings([])
|
||||||
|
} catch {
|
||||||
|
setMessageWarnings(['Invalid JSON'])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onChangeFunds(value: string) {
|
||||||
|
setFunds(value)
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (value !== '') JSON.parse(value)
|
||||||
|
setFundsWarnings([])
|
||||||
|
} catch {
|
||||||
|
setFundsWarnings(['Invalid JSON'])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='w-full flex flex-col gap-4'>
|
||||||
|
<Text>Execute Custom Message</Text>
|
||||||
|
<label>
|
||||||
|
<Text className='text-white/60 mb-1 text-xs'>Contract address</Text>
|
||||||
|
<input
|
||||||
|
value={contract}
|
||||||
|
onChange={(e) => setContract(e.target.value)}
|
||||||
|
className='bg-white/5 p-4 w-full text-sm'
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
<div className='flex items-center h-6 gap-2'>
|
||||||
|
<Text className='text-white/60 mb-1 text-xs'>Message</Text>
|
||||||
|
<WarningMessages messages={messageWarnings} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<textarea
|
||||||
|
value={message}
|
||||||
|
onChange={(e) => onChangeTextArea(e.target.value)}
|
||||||
|
className='text-white h-90 bg-white/5 p-4 w-full text-sm'
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<div className='flex items-center h-6 gap-2'>
|
||||||
|
<Text className='text-white/60 mb-1 text-xs'>Funds</Text>
|
||||||
|
<WarningMessages messages={fundsWarnings} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<textarea
|
||||||
|
value={funds}
|
||||||
|
onChange={(e) => onChangeFunds(e.target.value)}
|
||||||
|
className='text-white h-40 bg-white/5 p-4 w-full text-sm'
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<ActionButton
|
||||||
|
text='Execute'
|
||||||
|
onClick={() => {
|
||||||
|
execute(contract, JSON.parse(message), funds ? JSON.parse(funds) : [])
|
||||||
|
}}
|
||||||
|
disabled={fundsWarnings.length > 0 || !contract || messageWarnings.length > 0 || !message}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
@ -14,6 +14,7 @@ import {
|
|||||||
ActionCoin,
|
ActionCoin,
|
||||||
Action as CreditManagerAction,
|
Action as CreditManagerAction,
|
||||||
ExecuteMsg as CreditManagerExecuteMsg,
|
ExecuteMsg as CreditManagerExecuteMsg,
|
||||||
|
ExecuteMsg,
|
||||||
} from 'types/generated/mars-credit-manager/MarsCreditManager.types'
|
} from 'types/generated/mars-credit-manager/MarsCreditManager.types'
|
||||||
import { AccountKind } from 'types/generated/mars-rover-health-types/MarsRoverHealthTypes.types'
|
import { AccountKind } from 'types/generated/mars-rover-health-types/MarsRoverHealthTypes.types'
|
||||||
import { getAssetByDenom, getAssetBySymbol, getPythAssets } from 'utils/assets'
|
import { getAssetByDenom, getAssetBySymbol, getPythAssets } from 'utils/assets'
|
||||||
@ -184,6 +185,7 @@ export default function createBroadcastSlice(
|
|||||||
|
|
||||||
get().setToast({
|
get().setToast({
|
||||||
response,
|
response,
|
||||||
|
|
||||||
options: {
|
options: {
|
||||||
action: 'hls-staking',
|
action: 'hls-staking',
|
||||||
accountId: options.accountId,
|
accountId: options.accountId,
|
||||||
@ -194,6 +196,18 @@ export default function createBroadcastSlice(
|
|||||||
|
|
||||||
return response.then((response) => !!response.result)
|
return response.then((response) => !!response.result)
|
||||||
},
|
},
|
||||||
|
execute: async (contract: string, msg: ExecuteMsg, funds: Coin[]) => {
|
||||||
|
const response = get().executeMsg({
|
||||||
|
messages: [generateExecutionMessage(get().address, contract, msg, funds)],
|
||||||
|
})
|
||||||
|
|
||||||
|
get().setToast({
|
||||||
|
response,
|
||||||
|
options: { action: 'deposit', message: `Executed message` },
|
||||||
|
})
|
||||||
|
|
||||||
|
return response
|
||||||
|
},
|
||||||
borrow: async (options: { accountId: string; coin: BNCoin; borrowToWallet: boolean }) => {
|
borrow: async (options: { accountId: string; coin: BNCoin; borrowToWallet: boolean }) => {
|
||||||
const borrowAction: Action = { borrow: options.coin.toCoin() }
|
const borrowAction: Action = { borrow: options.coin.toCoin() }
|
||||||
const withdrawAction: Action = { withdraw: options.coin.toActionCoin() }
|
const withdrawAction: Action = { withdraw: options.coin.toActionCoin() }
|
||||||
|
1
src/types/interfaces/route.d.ts
vendored
1
src/types/interfaces/route.d.ts
vendored
@ -10,3 +10,4 @@ type Page =
|
|||||||
| 'hls-farm'
|
| 'hls-farm'
|
||||||
| 'hls-staking'
|
| 'hls-staking'
|
||||||
| 'governance'
|
| 'governance'
|
||||||
|
| 'execute'
|
||||||
|
1
src/types/interfaces/store/broadcast.d.ts
vendored
1
src/types/interfaces/store/broadcast.d.ts
vendored
@ -107,6 +107,7 @@ interface BroadcastSlice {
|
|||||||
isCreate: boolean
|
isCreate: boolean
|
||||||
kind: import('types/generated/mars-rover-health-types/MarsRoverHealthTypes.types').AccountKind
|
kind: import('types/generated/mars-rover-health-types/MarsRoverHealthTypes.types').AccountKind
|
||||||
}) => Promise<boolean>
|
}) => Promise<boolean>
|
||||||
|
execute: (contract: string, msg: ExecuteMsg, funds: Coin[]) => Promise<BroadcastResult>
|
||||||
executeMsg: (options: { messages: MsgExecuteContract[] }) => Promise<BroadcastResult>
|
executeMsg: (options: { messages: MsgExecuteContract[] }) => Promise<BroadcastResult>
|
||||||
lend: (options: { accountId: string; coin: BNCoin; isMax?: boolean }) => Promise<boolean>
|
lend: (options: { accountId: string; coin: BNCoin; isMax?: boolean }) => Promise<boolean>
|
||||||
reclaim: (options: { accountId: string; coin: BNCoin; isMax?: boolean }) => Promise<boolean>
|
reclaim: (options: { accountId: string; coin: BNCoin; isMax?: boolean }) => Promise<boolean>
|
||||||
|
@ -28,6 +28,7 @@ export function getRoute(
|
|||||||
|
|
||||||
export function getPage(pathname: string): Page {
|
export function getPage(pathname: string): Page {
|
||||||
const pages: Page[] = [
|
const pages: Page[] = [
|
||||||
|
'execute',
|
||||||
'trade',
|
'trade',
|
||||||
'trade-advanced',
|
'trade-advanced',
|
||||||
'perps',
|
'perps',
|
||||||
|
Loading…
Reference in New Issue
Block a user