Skip to content

Commit

Permalink
feat: add insurance config option
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Mar 22, 2023
1 parent c5d211b commit 9a3f0be
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
3 changes: 2 additions & 1 deletion packages/widget-playground/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ export const widgetBaseConfig: WidgetConfig = {
// disabledUI: ['toAddress', 'fromAmount', 'toToken', 'fromToken'],
// requiredUI: ['toAddress'],
// slippage: 0.003,
maxPriceImpact: 1,
insurance: true,
sdkConfig: {
apiUrl: 'https://develop.li.quest/v1',
defaultRouteOptions: {
maxPriceImpact: 1,
// slippage: 0.03,
// order: 'SAFEST',
// allowSwitchChain: false,
Expand Down
9 changes: 4 additions & 5 deletions packages/widget/src/hooks/useSwapRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const useSwapRoutes = ({
insurableRoute,
}: SwapRoutesProps = {}) => {
const lifi = useLiFi();
const { variant, sdkConfig, maxPriceImpact } = useWidgetConfig();
const { variant, sdkConfig, insurance } = useWidgetConfig();
const { account, provider } = useWallet();
const queryClient = useQueryClient();
const {
Expand Down Expand Up @@ -102,9 +102,9 @@ export const useSwapRoutes = ({
routePriority,
variant,
sdkConfig?.defaultRouteOptions?.allowSwitchChain,
maxPriceImpact,
enabledRefuel && enabledAutoRefuel,
gasRecommendation?.fromAmount,
insurance,
insurableRoute?.id,
];

Expand All @@ -131,9 +131,9 @@ export const useSwapRoutes = ({
routePriority,
variant,
allowSwitchChain,
maxPriceImpact,
enabledRefuel,
gasRecommendationFromAmount,
insurance,
insurableRouteId,
],
signal,
Expand Down Expand Up @@ -233,8 +233,7 @@ export const useSwapRoutes = ({
},
order: routePriority,
allowSwitchChain: variant === 'refuel' ? false : allowSwitchChain,
maxPriceImpact,
insurance: insurableRoute ? true : false,
insurance: insurance ? Boolean(insurableRoute) : undefined,
},
},
{ signal },
Expand Down
5 changes: 3 additions & 2 deletions packages/widget/src/pages/SwapPage/SwapPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const SwapPage: React.FC = () => {
const { t } = useTranslation();
const { setValue } = useFormContext();
const { navigateBack } = useNavigateBack();
const { variant } = useWidgetConfig();
const { variant, insurance } = useWidgetConfig();
const { state }: any = useLocation();
const stateRouteId = state?.routeId;
const [routeId, setRouteId] = useState<string>(stateRouteId);
Expand Down Expand Up @@ -80,11 +80,12 @@ export const SwapPage: React.FC = () => {
};

const SwapButton =
status === RouteExecutionStatus.Idle
insurance && status === RouteExecutionStatus.Idle
? StartIdleSwapButton
: StartSwapButton;

const insuranceAvailable =
insurance &&
variant !== 'refuel' &&
(route?.insurance?.state === 'INSURED' ||
(status === RouteExecutionStatus.Idle &&
Expand Down
7 changes: 5 additions & 2 deletions packages/widget/src/types/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ export interface SDKConfig
| 'disableVersionCheck'
| 'integrator'
> {
defaultRouteOptions?: Omit<RouteOptions, 'bridges' | 'exchanges'>;
defaultRouteOptions?: Omit<
RouteOptions,
'bridges' | 'exchanges' | 'insurance'
>;
}

export interface WidgetContractTool {
Expand Down Expand Up @@ -112,7 +115,7 @@ export interface WidgetConfig {

routePriority?: Order;
slippage?: number;
maxPriceImpact?: number;
insurance?: boolean;

variant?: WidgetVariant;

Expand Down

0 comments on commit 9a3f0be

Please sign in to comment.