BlueWallet/helpers/confirm.ts

34 lines
755 B
TypeScript
Raw Normal View History

2021-04-15 19:46:10 +02:00
import { Alert } from 'react-native';
import loc from '../loc';
/**
* Helper function that throws un-cancellable dialog to confirm user's action.
* Promise resolves to TRUE if user confirms, FALSE otherwise
*
* @param title {string}
* @param text {string}
*
* @return {Promise<boolean>}
*/
2022-09-05 20:34:02 +02:00
module.exports = function (title = 'Are you sure?', text = ''): Promise<boolean> {
2021-04-15 19:46:10 +02:00
return new Promise(resolve => {
Alert.alert(
title,
text,
[
{
text: loc._.yes,
onPress: () => resolve(true),
style: 'default',
},
{
text: loc._.cancel,
onPress: () => resolve(false),
style: 'cancel',
},
],
{ cancelable: false },
);
});
};