puted empty check

This commit is contained in:
u-e 2019-05-12 20:24:51 +03:00
parent 6024aa022b
commit 42fb6af774
7 changed files with 41 additions and 22 deletions

View File

@ -1,4 +1,6 @@
export default (input) => {
if (!input) return 0;
if (input === 0) {
return 25;
}

View File

@ -6,7 +6,10 @@ const readFromClipboard = async () => {
};
const writeToClipboard = async (text) => {
if (!text) return false;
await Clipboard.setString(text);
return true;
};

View File

@ -1,7 +1,14 @@
export const vestsToSp = (vests, steemPerMVests) => (vests / 1e6) * steemPerMVests;
export const vestsToSp = (vests, steemPerMVests) => {
if (!vests || !steemPerMVests) return 0;
return ((vests / 1e6) * steemPerMVests);
};
export const vestsToRshares = (vests, votingPower, votePerc) => {
if (!vests || !votingPower || !votePerc) return 0;
const vestingShares = parseInt(vests * 1e6, 10);
const power = (votingPower * votePerc) / 1e4 / 50 + 1;
return (power * vestingShares) / 1e4;
};

View File

@ -6,8 +6,10 @@ export const getWordsCount = text => (text && typeof text === 'string' ? text.re
const permlinkRnd = () => (Math.random() + 1).toString(16).substring(2);
export const generatePermlink = (title, random = false) => {
if (!title) return '';
const slug = getSlug(title);
let perm = slug.toString();
let perm = slug && slug.toString();
if (title) {
if (random) {
@ -32,6 +34,8 @@ export const generatePermlink = (title, random = false) => {
};
export const generateReplyPermlink = (toAuthor) => {
if (!toAuthor) return '';
const t = new Date(Date.now());
const timeFormat = `${t.getFullYear().toString()}${(
@ -48,6 +52,8 @@ export const generateReplyPermlink = (toAuthor) => {
};
export const makeOptions = (author, permlink, operationType) => {
if (!author || !permlink) return {};
const a = {
allow_curation_rewards: true,
allow_votes: true,
@ -63,10 +69,12 @@ export const makeOptions = (author, permlink, operationType) => {
a.max_accepted_payout = '1000000.000 SBD';
a.percent_steem_dollars = 0;
break;
case 'dp':
a.max_accepted_payout = '0.000 SBD';
a.percent_steem_dollars = 10000;
break;
default:
a.max_accepted_payout = '1000000.000 SBD';
a.percent_steem_dollars = 10000;
@ -97,8 +105,8 @@ export const extractMetadata = (body) => {
const out = {};
const mUrls = body.match(urlReg);
const mUsers = body.match(userReg);
const mUrls = body && body.match(urlReg);
const mUsers = body && body.match(userReg);
const matchedImages = [];
const matchedLinks = [];
@ -136,9 +144,11 @@ export const extractMetadata = (body) => {
};
export const createPatch = (text1, text2) => {
const dmp = new diff_match_patch();
if (!text1 && text1 === '') return undefined;
const dmp = new diff_match_patch();
const patches = dmp.patch_make(text1, text2);
const patch = dmp.patch_toText(patches);
return patch;
};

View File

@ -8,10 +8,13 @@ export default (posts, option) => {
});
return posts;
}
posts.map((post) => {
if (post.parent_permlink !== 'nsfw' && !post.json_metadata.tags.includes('nsfw')) {
updatedPosts.push(post);
}
});
return updatedPosts;
if (posts) {
posts.map((post) => {
if (post.parent_permlink !== 'nsfw' && !post.json_metadata.tags.includes('nsfw')) {
updatedPosts.push(post);
}
});
return updatedPosts;
}
};

View File

@ -49,23 +49,17 @@ export const catchEntryImage = (entry, width = 0, height = 0) => {
// try to extract images by regex
const imgReg2 = /(http(s?):)([/|.|\w|\s|-])*\.(?:jpe?g|gif|png)/gim;
const m = entry.body.match(imgReg2);
if (m) {
return proxifyImageSrc(m[0], width, height);
}
if (m) return proxifyImageSrc(m[0], width, height);
// If no image specified in json metadata, try extract first image href from entry body
let imgReg = /<img.+src=(?:"|')(.+?)(?:"|')(.*)>/;
let bodyMatch = entry.body.match(imgReg);
if (bodyMatch) {
return proxifyImageSrc(bodyMatch[1], width, height);
}
if (bodyMatch) return proxifyImageSrc(bodyMatch[1], width, height);
// If there is no <img> tag, check from markdown img tag ![](image.png)
imgReg = /(?:!\[(.*?)\]\((.*?)\))/;
bodyMatch = imgReg.exec(entry.body);
if (bodyMatch) {
return proxifyImageSrc(bodyMatch[2], width, height);
}
if (bodyMatch) return proxifyImageSrc(bodyMatch[2], width, height);
return null;
};
@ -73,7 +67,7 @@ export const catchEntryImage = (entry, width = 0, height = 0) => {
export const catchDraftImage = (body) => {
const imgRegex = /(https?:\/\/.*\.(?:tiff?|jpe?g|gif|png|svg|ico|PNG|GIF|JPG))/g;
if (imgRegex.test(body)) {
if (body && imgRegex.test(body)) {
const imageMatch = body.match(imgRegex);
return proxifyImageSrc(imageMatch[0]);

View File

@ -1,5 +1,5 @@
import { Linking } from 'react-native';
import qs from 'qs';
import { Linking } from 'react-native';
export const sendEmail = async (to, subject, body, options = {}) => {
const { cc, bcc } = options;