-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve proposal details visualization (#260)
## Description Closes: DPM-162, DPM-163, DPM-172, DPM-178 This PR enhances the visualization of the details of a governance proposal with the following changes: 1. Displays the proposal messages inside the scrollview instead of a horizontal list. 2. Generalizes the visualization of the modules `MsgUpdateParams` to display the changed parameters. 3. Adds the visualization of the proposal summary. 4. Shows the profile of the proposal's proposer. ###Final result: ![output](https://github.com/desmos-labs/dpm/assets/6245917/17ffb599-6fa2-4422-8bf2-ed593a5428f7) --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] provided a link to the relevant issue or specification - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed all author checklist items have been addressed
- Loading branch information
Showing
13 changed files
with
195 additions
and
158 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"signer": "Signer", | ||
"user": "User", | ||
"update params": "Update params" | ||
"update params": "Update params", | ||
"update module params": "Update {{ module }} module params", | ||
} |
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,90 @@ | ||
import { useNavigation } from '@react-navigation/native'; | ||
import { StackNavigationProp } from '@react-navigation/stack'; | ||
import TypographyContentLoaders from 'components/ContentLoaders/Typography'; | ||
import CopiableAddress from 'components/CopiableAddress'; | ||
import ProfileImage from 'components/ProfileImage'; | ||
import Spacer from 'components/Spacer'; | ||
import Typography from 'components/Typography'; | ||
import { makeStyle } from 'config/theme'; | ||
import useGetProfile from 'hooks/profile/useGetProfile'; | ||
import { getProfileDisplayName } from 'lib/ProfileUtils'; | ||
import { RootNavigatorParamList } from 'navigation/RootNavigator'; | ||
import ROUTES from 'navigation/routes'; | ||
import React from 'react'; | ||
import { View } from 'react-native'; | ||
import { TouchableOpacity } from 'react-native-gesture-handler'; | ||
import { DesmosProfile } from 'types/desmos'; | ||
|
||
interface InlineProfileProps { | ||
/** | ||
* Address of the profile to display. | ||
*/ | ||
readonly address: string; | ||
/** | ||
* Optional prefetched profile. | ||
*/ | ||
readonly profile?: DesmosProfile; | ||
} | ||
|
||
/** | ||
* Components that displays an user profile and if clicked opens the | ||
* profile screen. | ||
*/ | ||
const InlineProfile: React.FC<InlineProfileProps> = ({ address, profile }) => { | ||
const styles = useStyles(); | ||
const [toDisplayProfile, setToDisplayProfile] = React.useState(profile); | ||
const [profileLoading, setProfileLoading] = React.useState(profile === undefined); | ||
|
||
const navigation = useNavigation<StackNavigationProp<RootNavigatorParamList>>(); | ||
const getProfile = useGetProfile(); | ||
const showProfile = React.useCallback(() => { | ||
navigation.navigate(ROUTES.PROFILE, { | ||
visitingProfile: address, | ||
}); | ||
}, [address, navigation]); | ||
|
||
React.useEffect(() => { | ||
(async () => { | ||
if (profile === undefined) { | ||
setProfileLoading(true); | ||
const fetchedProfile = await getProfile(address); | ||
if (fetchedProfile.isOk()) { | ||
setToDisplayProfile(fetchedProfile.value); | ||
} | ||
setProfileLoading(false); | ||
} | ||
})(); | ||
}, [address, getProfile, profile]); | ||
|
||
if (toDisplayProfile === undefined && profileLoading === false) { | ||
return ( | ||
<View style={styles.root}> | ||
<CopiableAddress address={address} /> | ||
</View> | ||
); | ||
} | ||
|
||
return ( | ||
<TouchableOpacity onPress={showProfile}> | ||
<View style={styles.root}> | ||
<ProfileImage profile={toDisplayProfile} loading={profileLoading} size={32} /> | ||
<Spacer paddingLeft={8} /> | ||
{profileLoading ? ( | ||
<TypographyContentLoaders.Regular16 width={180} /> | ||
) : ( | ||
<Typography.Regular16>{getProfileDisplayName(toDisplayProfile!)}</Typography.Regular16> | ||
)} | ||
</View> | ||
</TouchableOpacity> | ||
); | ||
}; | ||
|
||
export default InlineProfile; | ||
|
||
const useStyles = makeStyle(() => ({ | ||
root: { | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
}, | ||
})); |
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
60 changes: 60 additions & 0 deletions
60
src/components/Messages/common/MsgUpdateParamsDetails/index.tsx
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,60 @@ | ||
import { EncodeObject } from '@desmoslabs/desmjs'; | ||
import { MessageDetailsComponent } from 'components/Messages/BaseMessage'; | ||
import BaseMessageDetails, { | ||
MessageDetailsField, | ||
} from 'components/Messages/BaseMessage/BaseMessageDetails'; | ||
import Typography from 'components/Typography'; | ||
import { formatCoin, formatCoins, isCoin } from 'lib/FormatUtils'; | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
const MsgUpdateParamsDetails: MessageDetailsComponent<EncodeObject> = ({ message }) => { | ||
const { t } = useTranslation('messages.common'); | ||
const moduleName = React.useMemo(() => { | ||
const [, name] = message.typeUrl.split('.'); | ||
return `${name[0].toUpperCase()}${name.substring(1)}`; | ||
}, [message.typeUrl]); | ||
|
||
const fields = React.useMemo<MessageDetailsField[]>(() => { | ||
const result: MessageDetailsField[] = []; | ||
Object.keys(message.value.params).forEach((key) => { | ||
const objectValue = message.value.params[key]; | ||
let serializedValue: string; | ||
|
||
if (typeof objectValue === 'object') { | ||
// Special case for the coin object. | ||
if (isCoin(objectValue)) { | ||
serializedValue = formatCoin(objectValue); | ||
} else if ( | ||
Object.prototype.toString.call(objectValue) === '[object Array]' && | ||
isCoin(objectValue[0]) | ||
) { | ||
// Special case for array of coins. | ||
serializedValue = formatCoins(objectValue); | ||
} else { | ||
serializedValue = JSON.stringify(objectValue, undefined, 4); | ||
} | ||
} else if (objectValue === null || objectValue === undefined) { | ||
serializedValue = 'null'; | ||
} else { | ||
serializedValue = objectValue.toString(); | ||
} | ||
|
||
result.push({ | ||
label: key, | ||
value: serializedValue, | ||
}); | ||
}); | ||
return result; | ||
}, [message.value]); | ||
|
||
return ( | ||
<BaseMessageDetails message={message} fields={fields}> | ||
<Typography.Regular14> | ||
{t('update module params', { module: moduleName })} | ||
</Typography.Regular14> | ||
</BaseMessageDetails> | ||
); | ||
}; | ||
|
||
export default MsgUpdateParamsDetails; |
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 was deleted.
Oops, something went wrong.
54 changes: 0 additions & 54 deletions
54
src/components/Messages/tokenfactory/MsgUpdateParamsDetails/index.tsx
This file was deleted.
Oops, something went wrong.
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.