lodash#isInteger JavaScript Examples
The following examples show how to use
lodash#isInteger.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.js From hzero-front with Apache License 2.0 | 7 votes |
/**
* getColLayout - 获取字段布局 包含对应的 style
* @param {Number} [col=3] 每行 列数
* @param {Number} colspan 字段宽度
*/
export function getColLayout(col = 3, colspan) {
const colL = cloneDeep(colLayout[col] || colLayout[3]);
if (isInteger(colspan) && colspan > 1) {
colL.span = min([24, colL.span * colspan]);
}
return colL;
}
Example #2
Source File: utils.js From hzero-front with Apache License 2.0 | 7 votes |
/**
* getColLayout - 获取字段布局 包含对应的 style
* @param {number} [col=3] 每行 列数
* @param {number} colspan 字段宽度
*/
export function getColLayout(col = 2, colspan) {
const colL = cloneDeep(colLayout[col] || colLayout[3]);
if (isInteger(colspan) && colspan > 1) {
colL.span = min([24, colL.span * colspan]);
}
return colL;
}
Example #3
Source File: index.js From datapass with GNU Affero General Public License v3.0 | 6 votes |
getStateFromUrlParams = (defaultState = {}) => {
const urlParams = new URLSearchParams(window.location.search);
return mapValues(defaultState, (value, key) => {
if (!urlParams.has(key)) {
return value;
}
const param = urlParams.getAll(key);
if (isObject(value)) {
return JSON.parse(param[0]);
}
if (isInteger(value)) {
return parseInt(param[0]) || value;
}
if (isBoolean(value)) {
return param[0] === 'true';
}
return param[0];
});
}
Example #4
Source File: index.js From hzero-front with Apache License 2.0 | 6 votes |
deleteRow() {
const { selectedRows, dataSource, pagination } = this.state;
const { handleDelete = e => e, roleDatasource = {} } = this.props;
const { current, pageSize } = pagination;
const { getFieldsValue = e => e } = this.queryForm;
const data = selectedRows.filter(o => isInteger(Number(o.key)));
this.setState({
dataSource: pullAllBy(
[...dataSource],
selectedRows.filter(o => !isInteger(Number(o.key)), 'key')
),
});
if (!isEmpty(data)) {
handleDelete(
data.map(n => ({
memberId: n.id,
roleId: roleDatasource.id,
})),
() => {
notification.success();
this.fetchDataSource({
roleId: roleDatasource.id,
page: current - 1,
size: pageSize,
...getFieldsValue(),
});
}
);
}
}
Example #5
Source File: index.js From hzero-front with Apache License 2.0 | 6 votes |
@Bind()
actionRender(text, record) {
const { editingRows } = this.state;
const operators = [
{
key: 'cancel',
ele: !isEmpty(editingRows.filter(o => o.key === record.key)) ? (
<a onClick={() => this.cancel(record)}>
{isInteger(Number(record.key))
? intl.get(`hzero.common.button.cancel`).d('取消')
: intl.get(`hzero.common.button.clean`).d('清除')}
</a>
) : (
<a onClick={() => this.edit(record)}>{intl.get(`hzero.common.button.edit`).d('编辑')}</a>
),
len: 2,
title: !isEmpty(editingRows.filter(o => o.key === record.key))
? isInteger(Number(record.key))
? intl.get(`hzero.common.button.cancel`).d('取消')
: intl.get(`hzero.common.button.clean`).d('清除')
: intl.get(`hzero.common.button.edit`).d('编辑'),
},
];
return operatorRender(operators);
}
Example #6
Source File: index.js From hzero-front with Apache License 2.0 | 6 votes |
@Bind()
cancel(record) {
const { dataSource, editingRows } = this.state;
const defaultItem = editingRows.find(o => o.key === record.key);
this.setState({
dataSource: isInteger(record.key)
? dataSource.map(n => (n.key === defaultItem.key ? defaultItem : n))
: dataSource.filter(o => o.key !== record.key),
editingRows: editingRows.filter(o => o.key !== record.key),
});
}
Example #7
Source File: index.js From hzero-front with Apache License 2.0 | 5 votes |
getSnapshotBeforeUpdate(prevProps) {
const { visible, roleDatasource } = this.props;
return (
visible && isInteger(roleDatasource.id) && roleDatasource.id !== prevProps.roleDatasource.id
);
}
Example #8
Source File: AddTokensToCarburetor.js From bonded-stablecoin-ui with MIT License | 4 votes |
AddTokensToCarburetor = () => {
const { activeWallet } = useSelector((state) => state.settings);
const { address: carburetorAddress, carburetor_balance } = useSelector((state) => state.carburetor);
const { params, reservePrice, oraclePrice, bonded_state, symbol1, symbol2, reserve_asset_symbol, address: curve_address } = useSelector((state) => state.active);
const [calculation, setCalculation] = useState(undefined);
const { m, n, decimals1, decimals2, reserve_asset_decimals } = params;
const { asset1, asset2 } = bonded_state;
const { t } = useTranslation();
const token1Button = useRef(null);
const token2Button = useRef(null);
const [countTokens1, setCountTokens1] = useState({ value: "", valid: undefined });
const [countTokens2, setCountTokens2] = useState({ value: "", valid: undefined });
const [withdrawAllChange, setWithdrawAllChange] = useState(false);
const amount1InCarburetor = carburetor_balance?.[asset1] || 0;
const amount2InCarburetor = carburetor_balance?.[asset2] || 0;
const amount1 = (Number(countTokens1.valid && countTokens1.value) || 0) + ((amount1InCarburetor / 10 ** decimals1) || 0);
const amount2 = (Number(countTokens2.valid && countTokens2.value) || 0) + ((amount2InCarburetor / 10 ** decimals2) || 0);
const { p2, dilution_factor, supply1, supply2 } = bonded_state;
const new_supply1 = supply1 - amount1 * 10 ** decimals1;
const new_supply2 = supply2 - amount2 * 10 ** decimals2;
const s1 = new_supply1 / 10 ** decimals1;
const s2 = new_supply2 / 10 ** decimals2;
const expectT1 = Math.abs(((p2 / (dilution_factor * n * (isInteger(n * 2) ? Math.sqrt(s2 ** ((n - 1) * 2)) : s2 ** (n - 1)))) ** (1 / m)) - (supply1 / 10 ** decimals1));
const expectT2 = Math.abs(((p2 / (dilution_factor * (s1 ** m) * n)) ** (1 / (n - 1))) - (supply2 / 10 ** decimals2));
let count1, count2;
if (expectT2 < amount2) {
count1 = amount1
count2 = expectT2;
} else if (expectT1 < amount1) {
count1 = expectT1;
count2 = amount2;
} else {
count1 = 0;
count2 = 0;
}
const actualParams = getParams(params, bonded_state);
useEffect(() => {
const get_exchange_result =
actualParams &&
$get_exchange_result({
tokens1: -(count1 * 10 ** decimals1),
tokens2: -(count2 * 10 ** decimals2),
params: actualParams,
vars: bonded_state,
oracle_price: oraclePrice,
timestamp: Math.floor(Date.now() / 1000),
reservePrice,
});
setCalculation(get_exchange_result);
}, [activeWallet, decimals1, decimals2, bonded_state, count1, count2]);
const [t1Form] = Form.useForm();
const [t2Form] = Form.useForm();
return <div>
<div>
<Form
size="large"
form={t1Form}
onValuesChange={(value) => {
if ("tokens1" in value) {
if (f(value.tokens1) <= decimals1) {
setCountTokens1((o) => ({ ...o, value: value.tokens1 }));
}
}
}}
>
<Form.Item
name="tokens1"
rules={[
{
validator: (_, value) =>
validator({
value,
name: "tokens1",
type: "number",
minValue: Number(1 / 10 ** decimals1).toFixed(decimals1),
maxDecimals: decimals1,
maxValue: bonded_state.supply1 / 10 ** decimals1,
onError: () => { setCountTokens1((o) => ({ ...o, valid: false })) },
onSuccess: () => { setCountTokens1((o) => ({ ...o, valid: true })) }
}),
},
]}
>
<Input
onKeyPress={(ev) => {
if (ev.key === "Enter" && token1Button.current && countTokens1.valid) {
token1Button.current.click();
}
}}
placeholder={t("modals.redeem-both.amount", "{{symbol}} amount", {symbol: symbol1 || "T1"})}
autoComplete="off"
suffix={symbol1 || "T1"}
ref={token1Button} />
</Form.Item>
</Form>
<QRButton
size="large"
style={{ marginBottom: 20 }}
type="primary"
ref={token1Button}
onClick={() => { t1Form.resetFields(); setCountTokens1({ value: "", valid: false }); }}
disabled={countTokens1 && !countTokens1.valid}
href={generateLink(Math.round((countTokens1.value || 0) * 10 ** decimals1), { curve_address, auto_withdraw: withdrawAllChange && amount2InCarburetor > 0 ? 1 : undefined }, activeWallet, carburetorAddress, bonded_state.asset1, true)}
>
{amount2InCarburetor > 0 ? t("modals.redeem-both.send_execute", "Send {{count}} {{symbol}} and execute", { count: countTokens1.valid ? countTokens1.value : "", symbol: symbol1 || "T1" }) : t("modals.redeem-both.send", "Send {{count}} {{symbol}}", { count: countTokens1.valid ? countTokens1.value : "", symbol: symbol1 || "T1" })}
</QRButton>
<Form
size="large"
form={t2Form}
onValuesChange={(value) => {
if ("tokens2" in value) {
if (f(value.tokens2) <= decimals2) {
setCountTokens2((o) => ({ ...o, value: value.tokens2 }));
}
}
}}
>
<Form.Item
name="tokens2"
rules={[
{
validator: (_, value) =>
validator({
value,
name: "tokens2",
type: "number",
minValue: Number(1 / 10 ** decimals2).toFixed(decimals2),
maxDecimals: decimals2,
maxValue: bonded_state.supply2 / 10 ** decimals2,
onError: () => { setCountTokens2((o) => ({ ...o, valid: false })) },
onSuccess: () => { setCountTokens2((o) => ({ ...o, valid: true })) }
}),
},
]}
>
<Input
onKeyPress={(ev) => {
if (ev.key === "Enter" && token2Button.current && countTokens2.valid) {
token2Button.current.click();
}
}}
placeholder={t("modals.redeem-both.amount", "{{symbol}} amount", {symbol: symbol2 || "T2"})}
autoComplete="off"
suffix={symbol2 || "T2"}
/>
</Form.Item>
</Form>
<QRButton
size="large"
type="primary"
ref={token2Button}
disabled={countTokens2 && !countTokens2.valid}
onClick={() => { t2Form.resetFields(); setCountTokens2({ value: "", valid: false }); }}
href={generateLink(Math.round((countTokens2.value || 0) * 10 ** decimals2), { curve_address, auto_withdraw: withdrawAllChange && amount1InCarburetor > 0 ? 1 : undefined }, activeWallet, carburetorAddress, bonded_state.asset2, true)}
>
{amount1InCarburetor > 0 ? t("modals.redeem-both.send_execute", "Send {{count}} {{symbol}} and execute", { count: countTokens2.valid ? countTokens2.value : "", symbol: symbol2 || "T2" }) : t("modals.redeem-both.send", "Send {{count}} {{symbol}}", { count: countTokens2.valid ? countTokens2.value : "", symbol: symbol2 || "T2" })}
</QRButton>
<div style={{ marginTop: 10, marginBottom: 10 }}>
<Checkbox checked={withdrawAllChange} onChange={(ev) => { setWithdrawAllChange(ev.target.checked) }}>{t("modals.redeem-both.withdraw_all_label", "Withdraw all the change when executing")}</Checkbox>
</div>
<div style={{ marginBottom: 10 }}>
<Text type="secondary">{t("modals.redeem-both.expect_values", "Expected values (tokens in the intermediary agent plus tokens in the fields)")}: </Text>
<Paragraph type="secondary" style={{ marginBottom: 10 }}>
<div>
<b>{t("modals.redeem-both.total", "Total {{symbol}} in the intermediary agent", {symbol: symbol1 || "T1"})}</b>: {amount1}
</div>
<div>
<b>{t("modals.redeem-both.total", "Total {{symbol}} in the intermediary agent", {symbol: symbol2 || "T2"})}</b>: {amount2}
</div>
{amount1 > 0 && amount2 > 0 && <>
<div>
<b>{t("modals.redeem-both.count_to_redeem", "Count {{symbol}} to redeem", {symbol: symbol1 || "T1"})}</b>: {+Number(count1).toFixed(decimals1)}
</div>
<div>
<b>{t("modals.redeem-both.count_to_redeem", "Count {{symbol}} to redeem", {symbol: symbol2 || "T2"})}</b>: {+Number(count2).toFixed(decimals2)}
</div>
<div>
<b>{t("modals.redeem-both.you_get", "You get {{count}} {{symbol}}", {count: calculation && Number(calculation.payout / 10 ** reserve_asset_decimals).toFixed(reserve_asset_decimals), symbol: reserve_asset_symbol})}.</b>
</div>
</>}
</Paragraph>
</div>
</div>
<Space wrap={true}>
<QRButton
size="large"
type="primary"
disabled={amount2InCarburetor === 0 && amount1InCarburetor === 0}
href={generateLink(1e4, { curve_address, withdraw: 1 }, activeWallet, carburetorAddress, "base", true)}
>
{t("modals.redeem-both.withdraw_all","Withdraw all")}
</QRButton>
</Space>
</div>
}
Example #9
Source File: index.js From hzero-front with Apache License 2.0 | 4 votes |
getColumns(defaultColumns) {
const { roleDatasource, resourceLevel, handleFetchHrunitsTree = e => e } = this.props;
const { editingRows, dataSource = [] } = this.state;
const saveBtnTarget = this.saveBtn;
const setRecord = newRecored => {
this.setState({
dataSource: dataSource.map(o => (o.key === newRecored.key ? newRecored : o)),
});
};
const getColumn = defaultColumn => {
const { dataIndex, title } = defaultColumn;
return dataIndex !== 'realName' && dataIndex !== 'tenantName'
? {
...defaultColumn,
render: (text, record) => {
const isUpdate = isInteger(Number(record.key));
const editing = !isEmpty(editingRows.filter(o => o.key === record.key));
const editable =
defaultColumn.className === 'editable-cell' ||
defaultColumn.className === 'editable-cell-operation';
const isColumnEdited = {
id: editing && !isUpdate,
assignLevel: editing, // editing && record.organizationId !== 0,
assignLevelValue: editing && record.assignLevel === 'org',
// editing && record.organizationId !== 0 && record.assignLevel === 'org',
};
const editableCellProps = {
title,
text,
dataIndex,
record,
saveBtnTarget,
editable,
editing: isColumnEdited[dataIndex],
currentEditingRow: find(editingRows, o => o.key === record.key),
roleTenantId: roleDatasource.tenantId,
roleTenantName: roleDatasource.tenantName,
setRecord,
// siteMeaning: getCodeMeaning('site', resourceLevel),
// 角色数据 需要传给 EditCell 来做判断
roleDatasource,
};
if (dataIndex === 'assignLevel') {
editableCellProps.options = assignResourceLevel(
resourceLevel,
roleDatasource,
record.organizationId,
roleDatasource.parentRoleAssignLevel
);
}
if (dataIndex === 'assignLevelValue') {
editableCellProps.handleFetchOrganizationData = handleFetchHrunitsTree;
editableCellProps.roleId = roleDatasource.id;
}
if (dataIndex === 'id') {
editableCellProps.roleId = roleDatasource.id;
}
return (
<EditableContext.Consumer>
{form =>
defaultColumn.className === 'editable-cell' ? (
<EditableCell form={form} {...editableCellProps} />
) : !isEmpty(editingRows.filter(o => o.key === record.key)) ? (
<a onClick={this.cancel.bind(this, record, form)}>
{isInteger(Number(record.key))
? intl.get(`hzero.common.button.cancel`).d('取消')
: intl.get(`hzero.common.button.clean`).d('清除')}
</a>
) : (
<a onClick={this.edit.bind(this, record, form)}>
{intl.get(`hzero.common.button.edit`).d('编辑')}
</a>
)}
</EditableContext.Consumer>
);
},
}
: defaultColumn;
};
return defaultColumns.map(n => getColumn(n));
}
Example #10
Source File: index.js From hzero-front with Apache License 2.0 | 4 votes |
@Bind()
getColumns2() {
const {
code = {},
roleDatasource,
resourceLevel,
handleFetchHrunitsTree = () => {},
} = this.props;
const { editingRows } = this.state;
const defaultColumns = [
{
title: intl.get(`hiam.roleManagement.model.roleManagement.userLoginName`).d('用户名'),
dataIndex: 'id',
render: (text, record) => record.realName,
},
!VERSION_IS_OP &&
currentTenantId === 0 && {
title: intl.get(`hiam.roleManagement.model.roleManagement.tenant`).d('所属租户'),
dataIndex: 'tenantName',
},
{
title: intl.get(`hiam.roleManagement.model.roleManagement.assignLevel`).d('分配层级'),
dataIndex: 'assignLevel',
width: 150,
render: (text, record) => record.assignLevelMeaning,
},
{
title: intl
.get(`hiam.roleManagement.model.roleManagement.assignLevelValue`)
.d('分配层级值'),
dataIndex: 'assignLevelValue',
width: 180,
render: (text, record) => record.assignLevelValueMeaning,
},
{
title: intl.get('hzero.common.button.action').d('操作'),
dataIndex: 'action',
width: 90,
fixed: 'right',
render: this.actionRender,
},
].filter(Boolean);
return defaultColumns.map(n => ({
...n,
onCell: record => {
const isUpdate = isInteger(Number(record.key));
const editing = !isEmpty(editingRows.filter(o => o.key === record.key));
const isColumnEdited = {
id: editing && !isUpdate,
assignLevel: editing, // editing && record.organizationId !== 0,
assignLevelValue: editing && record.assignLevel === 'org',
// editing && record.organizationId !== 0 && record.assignLevel === 'org',
};
const editableCellProps = {
record,
dataIndex: n.dataIndex,
title: n.title,
style: {
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
},
assignRowData: this.assignRowData,
onClick: e => {
const { target } = e;
if (target.style.whiteSpace === 'normal') {
target.style.whiteSpace = 'nowrap';
} else {
target.style.whiteSpace = 'normal';
}
},
editing: isColumnEdited[n.dataIndex],
contextConsumer: EditableContext.Consumer,
render: n.render,
code,
roleDatasource,
roleTenantId: roleDatasource.tenantId,
roleTenantName: roleDatasource.tenantName,
};
if (n.dataIndex === 'assignLevel') {
editableCellProps.options = assignResourceLevel(
resourceLevel,
roleDatasource,
record.organizationId,
roleDatasource.parentRoleAssignLevel
);
}
if (n.dataIndex === 'assignLevelValue') {
editableCellProps.handleFetchOrganizationData = handleFetchHrunitsTree;
editableCellProps.roleId = roleDatasource.id;
}
if (n.dataIndex === 'id') {
editableCellProps.roleId = roleDatasource.id;
}
return editableCellProps;
},
}));
}