/**
 * React Native Full App (https://store.enappd.com/product/react-native-full-app)
 *
 * Copyright © 2019-present Enappd. All rights reserved.
 *
 * This source code is licensed as per the terms found in the
 * LICENSE.md file in the root directory of this source tree.
 */

import { Toast } from 'native-base';

function showToast(msg:string, position?:"top"|"bottom") {
    Toast.show({
        text: msg,
        duration: 3000,
        position: position ? position : 'bottom',
        buttonText: ''
    })
}

function urlToBlob(url:string) {
    return new Promise((resolve, reject) => {
        const xhr = new XMLHttpRequest();
        xhr.onerror = reject;
        xhr.onreadystatechange = () => {
            if (xhr.readyState === 4) {
                resolve(xhr.response);
            }
        };
        xhr.open('GET', url);
        xhr.responseType = 'blob'; // convert type
        xhr.send();
    })
}

export { showToast, urlToBlob }; 
