@blocklet/ui-react
Version:
Some useful front-end web components that can be used in Blocklets.
31 lines (25 loc) • 1 kB
text/typescript
import type { AxiosError } from 'axios';
import { joinURL } from 'ufo';
import { createPassportSvg as _createPassportSvg, createKycSvg as _createKycSvg } from '@arcblock/ux/lib/Util/passport';
import { BLOCKLET_SERVICE_PATH_PREFIX } from '@arcblock/ux/lib/Util/constant';
import { CreatePassportProps } from '../../@types';
export const formatAxiosError = (err: AxiosError) => {
const { response } = err;
if (response) {
return `Request failed: ${response.status} ${response.statusText}: ${JSON.stringify(response.data)}`;
}
return err.message;
};
export const createPassportSvg = (props: CreatePassportProps) => {
if (props.scope === 'kyc') {
return _createKycSvg({
...props,
issuerAvatarUrl: joinURL(window.location.origin, BLOCKLET_SERVICE_PATH_PREFIX, '/blocklet/logo'),
type: props.role,
});
}
return _createPassportSvg({
...props,
issuerAvatarUrl: joinURL(window.location.origin, BLOCKLET_SERVICE_PATH_PREFIX, '/blocklet/logo'),
});
};