Skip to main content

Initializing the SDK

Before using any of the modules, you must initalize the SDK. This method needs to be called only once.

mport React, { useEffect, useState } from 'react';
import { AmaniSDK } from 'react-native-amani-sdk';

// in your component
const [isInitialized, setInitialized] = useState(false);
useEffect(() => {
AmaniSDK.sharedInstance
.initAmani({
server: 'https://example.server.ai',
idCardNumber: 'id card number of customer',
customerToken:
'profile token created from your back end',
lang: 'two letter language code',
useLocation: false,
version: "v2"
})
.then((initState) => setInitialized(initState))
.catch(() => setInitialized(false));
}, []);

Registering the event callbacks

For getting the errors from this SDK, and getting information about the profile of the KYC as well as getting the step results as the steps updated, you must set delegate callbacks.

Returned function from the setDelegate method is the cleanup function. Make sure to call it if you're initializing the sdk inside of a component to avoid memory leaks.

// continued from the previous code block inside useEffect
let unregisterHandle = AmaniSDK.sharedInstance.setDelegate({
onError: (type, body) => {
console.log({ type, body });
},
onProfileStatus: (body) => console.log(body),
onStepModel: (body) => console.log(body),
});

return () => {
unregisterHandle();
};

Understanding the module system

Each type of document has different modules that you can set the document type and capture with it. Modules uses the same pattern of containing start, setType and upload methods. Each start method can have different parameters, with subtle differences.