0.2.6 • Published 5 years ago
@kravc/expo-portal-agent v0.2.6
@kravc/expo-portal-agent
Portal agent helpers to be used by Expo applications.
Setup
Add packages to your expo project:
npm i --save @kravc/expo-portal-agent
npm i --save @kravc/expo-portal-polyfillsSetup polyfills and workarounds:
npx polyfillsConfigure issuer and credential types via @kravc/portal.
Connect Button
import React, { useState } from 'react'
import { Text, Button } from 'react-native'
import { useAgent } from '@kravc/expo-portal-agent'
const issuerId = 'ISSUER_ID'
const ConnectButton = function () {
  const onUsernamePress = onReset => [ () => onReset() ]
  const [ isInProgress, setIsInProgress ]   = useState(false)
  const [ onConnect, username, connectUrl ] = useAgent(issuerId, onUsernamePress, setIsInProgress)
  if (isInProgress) {
    return (
      <Text>
        Connecting...
      </Text>
    )
  }
  const title = username ? `@${username}` : 'Connect'
  return (
    <Button
      title={title}
      onPress={onConnect}
      connectUrl={connectUrl}
    />
  )
}
export default ConnectButtonIssue Credential
import { getAgent } from '@kravc/expo-portal-agent'
const issuerId         = 'ISSUER_ID'
const credentialTypeId = 'CREDENTIAL_TYPE_ID'
const issueCredentialAsync = (credentialSubject = {}) => {
  const agent = getAgent()
  if (!agent) {
    return
  }
  return agent.issueCredential(issuerId, credentialId, credentialSubject)
}