Various bug fixes (#435)

* fix: fixed the TxMessages issue

* fix: don’t show RewardsCenter if not connected

* fix: change deleteAccount message

* undo: rewert delete account fix
This commit is contained in:
Linkie Link 2023-09-06 19:40:36 +02:00 committed by GitHub
parent 0e62045031
commit f7917c1660
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 22 deletions

View File

@ -51,7 +51,7 @@ export default function DesktopHeader() {
) : ( ) : (
<div className='flex gap-4'> <div className='flex gap-4'>
{address && <AccountMenu />} {address && <AccountMenu />}
<RewardsCenter /> {address && <RewardsCenter />}
<Wallet /> <Wallet />
<Settings /> <Settings />
</div> </div>

View File

@ -122,12 +122,12 @@ export default function WalletConnectedButton() {
setShow={setShowDetails} setShow={setShowDetails}
> >
<div className='flex w-[440px] flex-wrap p-6'> <div className='flex w-[440px] flex-wrap p-6'>
<div className='flex-0 mb-4 flex w-full flex-nowrap items-start'> <div className='flex items-start w-full mb-4 flex-0 flex-nowrap'>
<div className='flex w-auto flex-1'> <div className='flex flex-1 w-auto'>
<div className='mr-2 flex h-[31px] items-end pb-0.5 text-base-caps'> <div className='mr-2 flex h-[31px] items-end pb-0.5 text-base-caps'>
{baseAsset.denom} {baseAsset.symbol}
</div> </div>
<div className='flex-0 flex flex-wrap justify-end'> <div className='flex flex-wrap justify-end flex-0'>
<FormattedNumber <FormattedNumber
animate animate
className='flex items-end text-2xl ' className='flex items-end text-2xl '
@ -139,8 +139,8 @@ export default function WalletConnectedButton() {
<Button color='secondary' onClick={onDisconnectWallet} text='Disconnect' /> <Button color='secondary' onClick={onDisconnectWallet} text='Disconnect' />
</div> </div>
</div> </div>
<div className='flex w-full flex-wrap'> <div className='flex flex-wrap w-full'>
<Text uppercase className='/80 mb-1 break-all'> <Text uppercase className='mb-1 break-all /80'>
{'Your Address'} {'Your Address'}
</Text> </Text>
@ -154,7 +154,7 @@ export default function WalletConnectedButton() {
<Button <Button
leftIcon={isCopied ? <Check /> : <Copy />} leftIcon={isCopied ? <Check /> : <Copy />}
variant='transparent' variant='transparent'
className='mr-10 flex w-auto py-2' className='flex w-auto py-2 mr-10'
color='quaternary' color='quaternary'
onClick={setCopied} onClick={setCopied}
text={isCopied ? 'Copied' : 'Copy Address'} text={isCopied ? 'Copied' : 'Copy Address'}

View File

@ -13,7 +13,7 @@ import {
ExecuteMsg as CreditManagerExecuteMsg, ExecuteMsg as CreditManagerExecuteMsg,
} from 'types/generated/mars-credit-manager/MarsCreditManager.types' } from 'types/generated/mars-credit-manager/MarsCreditManager.types'
import { getAssetByDenom, getAssetBySymbol } from 'utils/assets' import { getAssetByDenom, getAssetBySymbol } from 'utils/assets'
import { getSingleValueFromBroadcastResult } from 'utils/broadcast' import { generateErrorMessage, getSingleValueFromBroadcastResult } from 'utils/broadcast'
import checkAutoLendEnabled from 'utils/checkAutoLendEnabled' import checkAutoLendEnabled from 'utils/checkAutoLendEnabled'
import { defaultFee } from 'utils/constants' import { defaultFee } from 'utils/constants'
import { formatAmountWithSymbol } from 'utils/formatters' import { formatAmountWithSymbol } from 'utils/formatters'
@ -51,12 +51,11 @@ export default function createBroadcastSlice(
}, },
}) })
} else { } else {
const error = response.error ? response.error : response.result?.rawLogs
set({ set({
toast: { toast: {
message: errorMessage ?? `Transaction failed: ${error}`, message: generateErrorMessage(response, errorMessage),
isError: true, isError: true,
hash: response.result.hash, hash: response.result?.hash,
}, },
}) })
} }
@ -134,7 +133,7 @@ export default function createBroadcastSlice(
messages: [generateExecutionMessage(get().address, ENV.ADDRESS_CREDIT_MANAGER, msg, [])], messages: [generateExecutionMessage(get().address, ENV.ADDRESS_CREDIT_MANAGER, msg, [])],
}) })
if (response.result) { if (response.result && !response.error) {
set({ createAccountModal: false }) set({ createAccountModal: false })
const id = getSingleValueFromBroadcastResult(response.result, 'wasm', 'token_id') const id = getSingleValueFromBroadcastResult(response.result, 'wasm', 'token_id')
set({ set({
@ -146,11 +145,8 @@ export default function createBroadcastSlice(
set({ set({
createAccountModal: false, createAccountModal: false,
toast: { toast: {
message: message: generateErrorMessage(response),
response.error && response.error !== 'Transaction failed' hash: response?.result?.hash,
? `Transaction failed: ${response.error}`
: 'Transaction rejected by user',
hash: response.result?.hash ?? undefined,
isError: true, isError: true,
}, },
}) })

View File

@ -2,7 +2,7 @@ const BNCoin = import('types/classes/BNCoin').BNCoin
const ActionCoin = import('types/generated').ActionCoin const ActionCoin = import('types/generated').ActionCoin
interface BroadcastResult { interface BroadcastResult {
result?: import('@delphi-labs/shuttle-react').TxBroadcastResult result?: import('@delphi-labs/shuttle-react').BroadcastResult
error?: string error?: string
} }

View File

@ -1,7 +1,5 @@
import { BroadcastResult } from '@delphi-labs/shuttle-react'
export function getSingleValueFromBroadcastResult( export function getSingleValueFromBroadcastResult(
response: BroadcastResult, response: BroadcastResult['result'],
messageType: string, messageType: string,
messageKey: string, messageKey: string,
): string | null { ): string | null {
@ -14,3 +12,10 @@ export function getSingleValueFromBroadcastResult(
if (!value) return null if (!value) return null
return value return value
} }
export function generateErrorMessage(result: BroadcastResult, errorMessage?: string) {
const error = result.error ? result.error : result.result?.rawLogs
if (errorMessage) return errorMessage
if (error === 'Transaction failed') return 'Transaction rejected by user'
return `Transaction failed: ${error}`
}