Skip to content

Commit

Permalink
fix: W3C fixes (#205)
Browse files Browse the repository at this point in the history
* fix: w3c fixes

Signed-off-by: Sai Ranjit Tummalapalli <[email protected]>

* chore: bump ios version

Signed-off-by: Sai Ranjit Tummalapalli <[email protected]>

* fix: delete credential delay

Signed-off-by: Sai Ranjit Tummalapalli <[email protected]>

---------

Signed-off-by: Sai Ranjit Tummalapalli <[email protected]>
  • Loading branch information
sairanjit committed Jul 6, 2024
1 parent e90a730 commit fc67c27
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 50 deletions.
20 changes: 6 additions & 14 deletions app/components/record/W3CCredentialRecord.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ export interface RecordProps {
const W3CCredentialRecord: React.FC<RecordProps> = ({
header,
footer,
fields,
hideFieldValues = false,
tables,
w3cCredential,
renderCertificate,
}) => {
const { t } = useTranslation()
const [shown, setShown] = useState<boolean[]>([])
const [showAll, setShowAll] = useState<boolean>(false)
const [shown, setShown] = useState<boolean[][]>([])
const [showAll, setShowAll] = useState<boolean>(true)
const { ListItems, TextTheme, ColorPallet } = useTheme()

const styles = StyleSheet.create({
Expand Down Expand Up @@ -66,19 +65,13 @@ const W3CCredentialRecord: React.FC<RecordProps> = ({
})

const resetShown = (): void => {
setShown(fields.map(() => showAll))
setShown(tables.map(table => table.rows.map(() => showAll)))
setShowAll(!showAll)
}

const toggleShownState = (newShowStates: boolean[]): void => {
if (newShowStates.filter(shownState => shownState === showAll).length > Math.floor(fields.length / 2)) {
setShowAll(!showAll)
}
}

useEffect(() => {
resetShown()
}, [])
}, [tables])

return (
<FlatList
Expand Down Expand Up @@ -110,11 +103,10 @@ const W3CCredentialRecord: React.FC<RecordProps> = ({
hideFieldValue={hideFieldValues}
onToggleViewPressed={() => {
const newShowState = [...shown]
newShowState[index] = !shown[index]
newShowState[index][idx] = !shown[index][idx]
setShown(newShowState)
toggleShownState(newShowState)
}}
shown={hideFieldValues ? !!shown[index] : true}
shown={hideFieldValues ? !!(shown?.[index]?.[idx] ?? false) : true}
hideBottomBorder={idx === table.rows.length - 1}
/>
))}
Expand Down
2 changes: 1 addition & 1 deletion app/components/record/W3CCredentialRecordField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const W3CCredentialRecordField: React.FC<W3CCredentialRecordFieldProps> = ({
) : null}
</>
</View>
{<View style={[styles.border, hideBottomBorder && { borderBottomWidth: 0 }]} />}
<View style={[styles.border, hideBottomBorder && { borderBottomWidth: 0 }]} />
</View>
)
}
Expand Down
2 changes: 1 addition & 1 deletion app/navigators/ContactStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const ContactStack: React.FC = () => {
<Stack.Screen
name={Screens.CredentialDetailsW3C}
component={CredentialDetailsW3C}
options={{ title: t('Screens.CredentialDetailsW3C') }}
options={{ title: t('Screens.CredentialDetails') }}
/>
<Stack.Screen
name={Screens.CredentialOffer}
Expand Down
2 changes: 1 addition & 1 deletion app/navigators/CredentialStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const CredentialStack: React.FC = () => {
<Stack.Screen
name={Screens.CredentialDetailsW3C}
component={CredentialDetailsW3C}
options={{ title: t('Screens.CredentialDetailsW3C') }}
options={{ title: t('Screens.CredentialDetails') }}
/>
<Stack.Screen
name={Screens.RenderCertificate}
Expand Down
12 changes: 10 additions & 2 deletions app/screens/CredentialDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const CredentialDetails: React.FC<CredentialDetailsProps> = ({ navigation, route
const [isRevoked, setIsRevoked] = useState<boolean>(false)
const [revocationDate, setRevocationDate] = useState<string>('')
const [preciseRevocationDate, setPreciseRevocationDate] = useState<string>('')
const [isDeletingCredential, setIsDeletingCredential] = useState<boolean>(false)
const [isRemoveModalDisplayed, setIsRemoveModalDisplayed] = useState<boolean>(false)
const [isRevokedMessageHidden, setIsRevokedMessageHidden] = useState<boolean>(
(credential!.metadata.get(CredentialMetadata.customMetadata) as customMetadata)?.revoked_detail_dismissed ?? false,
Expand Down Expand Up @@ -194,19 +195,25 @@ const CredentialDetails: React.FC<CredentialDetailsProps> = ({ navigation, route
if (!credential) {
return
}
setIsDeletingCredential(true)

await deleteCredentialExchangeRecordById(agent, credential.id)
await deleteCredentialExchangeRecordById(agent, credential.id, {
deleteAssociatedCredentials: true,
})

setIsDeletingCredential(false)

navigation.pop()

// FIXME: This delay is a hack so that the toast doesn't appear until the modal is dismissed
await new Promise(resolve => setTimeout(resolve, 1000))
await new Promise(resolve => setTimeout(resolve, 50))

Toast.show({
type: ToastType.Success,
text1: t('CredentialDetails.CredentialRemoved'),
})
} catch (err: unknown) {
setIsDeletingCredential(false)
const error = new BifoldError(t('Error.Title1032'), t('Error.Message1032'), (err as Error).message, 1025)

DeviceEventEmitter.emit(EventTypes.ERROR_ADDED, error)
Expand Down Expand Up @@ -416,6 +423,7 @@ const CredentialDetails: React.FC<CredentialDetailsProps> = ({ navigation, route
visible={isRemoveModalDisplayed}
onSubmit={callSubmitRemove}
onCancel={callCancelRemove}
disabled={isDeletingCredential}
/>
</SafeAreaView>
)
Expand Down
23 changes: 17 additions & 6 deletions app/screens/CredentialDetailsW3C.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import {
CredentialExchangeRecord,
W3cCredentialRecord,
getW3cCredentialRecordById,
getAllCredentialExchangeRecords,
deleteCredentialExchangeRecordById,
useCredentialByState,
CredentialState,
} from '@adeya/ssi'
import { BrandingOverlay } from '@hyperledger/aries-oca'
import { CredentialOverlay } from '@hyperledger/aries-oca/build/legacy'
Expand Down Expand Up @@ -54,6 +55,8 @@ const CredentialDetailsW3C: React.FC<CredentialDetailsProps> = ({ navigation, ro
const [isRemoveModalDisplayed, setIsRemoveModalDisplayed] = useState<boolean>(false)
const [tables, setTables] = useState<W3CCredentialAttributeField[]>([])
const [w3cCredential, setW3cCredential] = useState<W3cCredentialRecord>()
const credentialsList = useCredentialByState(CredentialState.Done)
const [isDeletingCredential, setIsDeletingCredential] = useState<boolean>(false)

const [overlay, setOverlay] = useState<CredentialOverlay<BrandingOverlay>>({
bundle: undefined,
Expand Down Expand Up @@ -160,18 +163,25 @@ const CredentialDetailsW3C: React.FC<CredentialDetailsProps> = ({ navigation, ro
if (!(agent && credential)) {
return
}
const credentialList = await getAllCredentialExchangeRecords(agent)
const rec = credentialList.find(cred => cred.credentials[0]?.credentialRecordId === credential.id)
const rec = credentialsList.find(cred => cred.credentials[0]?.credentialRecordId === credential.id)
setIsDeletingCredential(true)
if (rec) {
await deleteCredentialExchangeRecordById(agent, rec.id)
await deleteCredentialExchangeRecordById(agent, rec.id, {
deleteAssociatedCredentials: true,
})
}
setIsDeletingCredential(false)
navigation.pop()

// FIXME: This delay is a hack so that the toast doesn't appear until the modal is dismissed
await new Promise(resolve => setTimeout(resolve, 50))

Toast.show({
type: ToastType.Success,
text1: t('CredentialDetails.CredentialRemoved'),
})

navigation.pop()
} catch (err: unknown) {
setIsDeletingCredential(false)
const error = new BifoldError(t('Error.Title1032'), t('Error.Message1032'), (err as Error).message, 1025)

DeviceEventEmitter.emit(EventTypes.ERROR_ADDED, error)
Expand Down Expand Up @@ -319,6 +329,7 @@ const CredentialDetailsW3C: React.FC<CredentialDetailsProps> = ({ navigation, ro
visible={isRemoveModalDisplayed}
onSubmit={callSubmitRemove}
onCancel={callCancelRemove}
disabled={isDeletingCredential}
/>
</SafeAreaView>
)
Expand Down
3 changes: 2 additions & 1 deletion app/screens/ImportWalletConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
SingleContextStorageLruCache,
CacheModule,
MediatorPickupStrategy,
WebDidResolver,
} from '@adeya/ssi'
import { PolygonDidResolver, PolygonModule } from '@ayanworks/credo-polygon-w3c-module'
import { StackScreenProps } from '@react-navigation/stack'
Expand Down Expand Up @@ -159,7 +160,7 @@ const ImportWalletVerify: React.FC<ImportWalletVerifyProps> = ({ navigation }) =
}),
polygon: new PolygonModule({}),
dids: new DidsModule({
resolvers: [new PolygonDidResolver(), new IndyVdrIndyDidResolver()],
resolvers: [new PolygonDidResolver(), new IndyVdrIndyDidResolver(), new WebDidResolver()],
}),
cache: new CacheModule({
cache: new SingleContextStorageLruCache({
Expand Down
43 changes: 22 additions & 21 deletions app/screens/ListCredentials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
useCredentialByState,
CredentialExchangeRecord,
CredentialState,
findConnectionById,
getW3cCredentialRecordById,
useConnections,
getAllW3cCredentialRecords,
} from '@adeya/ssi'
import { useNavigation } from '@react-navigation/core'
import { StackNavigationProp } from '@react-navigation/stack'
Expand Down Expand Up @@ -42,6 +42,7 @@ const ListCredentials: React.FC = () => {
...useCredentialByState(CredentialState.Done),
]
const [credentialList, setCredentialList] = useState<(CredentialExchangeRecord | EnhancedW3CRecord)[] | undefined>([])
const { records: connectionRecords } = useConnections()

const navigation = useNavigation<StackNavigationProp<CredentialStackParams>>()
const { ColorPallet } = useTheme()
Expand All @@ -52,33 +53,33 @@ const ListCredentials: React.FC = () => {
return
}

const updatedCredentials = await Promise.all(
credentials.map(async credential => {
if (isW3CCredential(credential)) {
const credentialRecordId = credential.credentials[0].credentialRecordId
try {
const record = await getW3cCredentialRecordById(agent, credentialRecordId)
if (!credential?.connectionId) {
throw new Error('Connection Id notfound')
}
const connection = await findConnectionById(agent, credential?.connectionId)
const enhancedRecord = record as EnhancedW3CRecord
enhancedRecord.connectionLabel = connection?.theirLabel
return enhancedRecord
} catch (e: unknown) {
throw new Error(`${e}`)
const w3cCredentialRecords = await getAllW3cCredentialRecords(agent)

const updatedCredentials = credentials.map(credential => {
if (isW3CCredential(credential)) {
const credentialRecordId = credential.credentials[0].credentialRecordId
try {
const record = w3cCredentialRecords.find(record => record.id === credentialRecordId)
if (!credential?.connectionId) {
throw new Error('Connection Id notfound')
}
const connection = connectionRecords.find(connection => connection.id === credential?.connectionId)
const enhancedRecord = record as EnhancedW3CRecord
enhancedRecord.connectionLabel = connection?.theirLabel
return enhancedRecord
} catch (e: unknown) {
throw new Error(`${e}`)
}
return credential
}),
)
}
return credential
})
return updatedCredentials
}

updateCredentials().then(updatedCredentials => {
setCredentialList(updatedCredentials)
})
}, [])
}, [credentials])

return (
<View style={styles.container}>
Expand Down
3 changes: 2 additions & 1 deletion app/screens/Splash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
CacheModule,
SingleContextStorageLruCache,
MediatorPickupStrategy,
WebDidResolver,
} from '@adeya/ssi'
import { PolygonDidResolver, PolygonModule } from '@ayanworks/credo-polygon-w3c-module'
import AsyncStorage from '@react-native-async-storage/async-storage'
Expand Down Expand Up @@ -298,7 +299,7 @@ const Splash: React.FC = () => {
}),
polygon: new PolygonModule({}),
dids: new DidsModule({
resolvers: [new PolygonDidResolver(), new IndyVdrIndyDidResolver()],
resolvers: [new PolygonDidResolver(), new IndyVdrIndyDidResolver(), new WebDidResolver()],
}),
cache: new CacheModule({
cache: new SingleContextStorageLruCache({
Expand Down
4 changes: 2 additions & 2 deletions ios/AdeyaWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = AdeyaWallet/AdeyaWallet.entitlements;
CURRENT_PROJECT_VERSION = 32;
CURRENT_PROJECT_VERSION = 33;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = Z5W7KRPGHZ;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -545,7 +545,7 @@
CODE_SIGN_ENTITLEMENTS = AdeyaWallet/AdeyaWallet.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 32;
CURRENT_PROJECT_VERSION = 33;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = Z5W7KRPGHZ;
INFOPLIST_FILE = AdeyaWallet/Info.plist;
Expand Down

0 comments on commit fc67c27

Please sign in to comment.