Skip to content

Commit

Permalink
fix(partnerConfig): add alerts for estimating creation of CMAccount &…
Browse files Browse the repository at this point in the history
… fix matching with fresh accounts
  • Loading branch information
aeddaqqa committed Sep 20, 2024
1 parent 21957ad commit f25d434
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 15 deletions.
30 changes: 26 additions & 4 deletions src/components/Alert.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { Box, Typography } from '@mui/material'
import { Box, SxProps, Typography } from '@mui/material'
import React from 'react'

const Alert = ({
variant,
title,
content,
sx,
}: {
variant: 'info' | 'negative'
variant: 'info' | 'negative' | 'warning'
title?: string
content: string
sx?: SxProps
}) => {
return (
<Box
Expand All @@ -18,11 +20,20 @@ const Alert = ({
padding: '16px',
border: '1px solid',
borderColor:
variant === 'info' ? 'rgba(0, 133, 255, 0.5)' : 'rgba(229, 67, 31, 0.5)',
variant === 'info'
? 'rgba(0, 133, 255, 0.5)'
: variant === 'warning'
? 'rgba(229, 162, 31, 0.5)'
: 'rgba(229, 67, 31, 0.5)',
background:
variant === 'info' ? 'rgba(0, 133, 255, 0.05)' : 'rgba(229, 67, 31, 0.05)',
variant === 'info'
? 'rgba(0, 133, 255, 0.05)'
: variant === 'warning'
? 'rgba(229, 162, 31, 0.05)'
: 'rgba(229, 67, 31, 0.05)',
borderRadius: '6px',
maxWidth: '350px',
...sx,
...(!title && { alignItems: 'center' }),
}}
>
Expand Down Expand Up @@ -55,6 +66,17 @@ const Alert = ({
/>
</svg>
)}
{variant === 'warning' && (
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path d="M13 14H11V9H13M13 18H11V16H13M1 21H23L12 2L1 21Z" fill="#E5A21F" />
</svg>
)}
</Box>
<Box sx={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
{title && (
Expand Down
3 changes: 0 additions & 3 deletions src/helpers/useSmartContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ export const SmartContractProvider: React.FC<SmartContractProviderProps> = ({ ch
)
setProvider(ethersProvider)
setManagerReadContract(managerReadOnlyContract)
// const allCMAccounts = await getCMAccountMappings()
// let result = allCMAccounts.getAllMappings()
// console.log(result)
} catch (error) {
console.error('User denied account access:', error)
}
Expand Down
2 changes: 1 addition & 1 deletion src/redux/services/partners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async function getContractMappings(): Promise<Map<string, string>> {

function checkMatch(data): boolean {
if (data.supportedResult.length === 0 && data.wantedResult.length === 0) {
return true
return false
}

const supportedResultSet = new Set(data.supportedResult.map(getServiceName))
Expand Down
1 change: 0 additions & 1 deletion src/views/partners/ConfigurSupplier.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ export const BasicSupportedServices = () => {
})
useEffect(() => {
if (partner) {
console.log({ supportedServices: partner.supportedServices })
dispatchSupplierState({
type: actionTypes.UPDATE_SUPPORTED_SERVICES,
payload: { services: partner.supportedServices, reset: true },
Expand Down
19 changes: 18 additions & 1 deletion src/views/partners/Configuration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ const Content = () => {
const { state, dispatch } = usePartnerConfigurationContext()
const [loading, setLoading] = useState(false)
const partnerConfig = usePartnerConfig()

async function submit() {
setLoading(true)
await partnerConfig.CreateConfiguration(state)
setLoading(false)
}
const { balance } = useWalletBalance()

if (contractCMAccountAddress) return <MyMessenger />
return (
<Box
Expand Down Expand Up @@ -66,10 +68,25 @@ const Content = () => {
)}
<Divider />
<Configuration.Buttons>
<MainButton loading={loading} variant="contained" onClick={submit}>
<MainButton
loading={loading}
variant="contained"
onClick={submit}
disabled={parseFloat(balance) < 100}
>
Create Configuration
</MainButton>
</Configuration.Buttons>
<Box sx={{ width: '100%' }}>
<Alert
sx={{ maxWidth: 'none', width: 'fit-content' }}
variant="warning"
title="100 CAM is required"
content={
'Creating Camino Messenger account will incur a fee estimated of 0.22366775 CAM from C-Chain balance'
}
/>
</Box>
</Configuration>
<Box sx={{ display: 'flex', flexDirection: 'column', gap: '16px' }}>
{state.step === 0 && (
Expand Down
33 changes: 31 additions & 2 deletions src/views/partners/MyMessenger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -454,15 +454,23 @@ const MyMessenger = () => {
Offered Services
</Typography>
<Typography variant="caption">
{getServicesNames(state.stepsConfig[1]?.services)}
{state.stepsConfig[1]?.services.length > 0 ? (
getServicesNames(state.stepsConfig[1]?.services)
) : (
<>None</>
)}
</Typography>
</Box>
<Box sx={{ display: 'flex', alignItems: 'start', gap: '16px' }}>
<Typography sx={{ flex: '0 0 20%' }} variant="body2">
Wanted Services
</Typography>
<Typography variant="caption">
{getServicesNames(state.stepsConfig[2]?.services)}
{state.stepsConfig[2]?.services.length > 0 ? (
getServicesNames(state.stepsConfig[2]?.services)
) : (
<>None</>
)}
</Typography>
</Box>
{/* <ServiceList
Expand Down Expand Up @@ -679,6 +687,27 @@ const MyMessenger = () => {
)}
</Box>
</Box>
{state.stepsConfig[1]?.services.length == 0 && (
<Alert
sx={{ maxWidth: 'none', width: 'fit-content' }}
variant="warning"
content="Visit the relevant tab to add offered services"
/>
)}
{state.stepsConfig[2]?.services.length == 0 && (
<Alert
sx={{ maxWidth: 'none', width: 'fit-content' }}
variant="warning"
content="Visit the relevant tab to add wanted services"
/>
)}
{bots.length == 0 && (
<Alert
sx={{ maxWidth: 'none', width: 'fit-content' }}
variant="warning"
content="Visit the relevant tab to add bots"
/>
)}
</Configuration>
<Box sx={{ display: 'flex', flexDirection: 'column', gap: '16px' }}>
<Configuration.Infos
Expand Down
8 changes: 5 additions & 3 deletions src/views/partners/Partner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,11 @@ const Widget = ({ supportedServices, CMAccountAddress, wantedServices, supported
)}
{!supportedCurrencies?.offChainPaymentSupported &&
!supportedCurrencies?.isCam && (
<Typography fontSize={14} fontWeight={600} lineHeight={'20px'}>
None.
</Typography>
<li className="service-type-item">
<Typography fontSize={14} fontWeight={600} lineHeight={'20px'}>
None.
</Typography>
</li>
)}
</ul>
) : (
Expand Down

0 comments on commit f25d434

Please sign in to comment.