Skip to content

Commit 911d402

Browse files
authored
Merge pull request #135 from polymorpher/spending-manager
v12: Extend daily limit to "spending limit"; Allow arbitrary time interval for spending limit; New library "SpendingManager"; Allow multiple contract calls in one operation; Fix various issues
2 parents 150297c + dfff8fd commit 911d402

30 files changed

Lines changed: 126841 additions & 107591 deletions

code/build/contracts/CommitManager.json

Lines changed: 22246 additions & 15909 deletions
Large diffs are not rendered by default.

code/build/contracts/IONEWallet.json

Lines changed: 2368 additions & 2170 deletions
Large diffs are not rendered by default.

code/build/contracts/ONEWallet.json

Lines changed: 76389 additions & 73058 deletions
Large diffs are not rendered by default.

code/build/contracts/SpendingManager.json

Lines changed: 9204 additions & 0 deletions
Large diffs are not rendered by default.

code/build/contracts/TokenManager.json

Lines changed: 5272 additions & 5272 deletions
Large diffs are not rendered by default.

code/build/contracts/TokenTracker.json

Lines changed: 5482 additions & 5482 deletions
Large diffs are not rendered by default.

code/build/contracts/WalletGraph.json

Lines changed: 5506 additions & 5506 deletions
Large diffs are not rendered by default.

code/client/src/components/AddressInput.jsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ const AddressInput = ({ setAddressCallback, currentWallet, addressValue, extraSe
146146

147147
if (validAddress) {
148148
const existingKnownAddress = knownAddresses[validAddress]
149-
149+
// console.log(addressObject)
150150
setAddressCallback(addressObject.label
151151
? {
152152
...addressObject,
@@ -222,10 +222,8 @@ const AddressInput = ({ setAddressCallback, currentWallet, addressValue, extraSe
222222
filterValue
223223
}) => {
224224
const oneAddress = util.safeOneAddress(address)
225-
const addressDisplay = util.shouldShortenAddress({ label: label, isMobile })
226-
? util.ellipsisAddress(oneAddress)
227-
: oneAddress
228-
225+
const addressDisplay = util.shouldShortenAddress({ label, isMobile }) ? util.ellipsisAddress(oneAddress) : oneAddress
226+
const displayLabel = `${label ? `(${label})` : ''} ${addressDisplay}`
229227
return (
230228
<Select.Option key={addressDisplay} value={filterValue} style={{ padding: 0 }}>
231229
<Row align='left'>
@@ -236,7 +234,7 @@ const AddressInput = ({ setAddressCallback, currentWallet, addressValue, extraSe
236234
type='text'
237235
style={{ textAlign: 'left', height: '100%', padding: '5px' }}
238236
onClick={() => {
239-
onSelectAddress({ value: address, label: addressDisplay, key, domainName })
237+
onSelectAddress({ value: address, label: displayLabel, key, domainName })
240238
}}
241239
>
242240
<Space direction={isMobile ? 'vertical' : 'horizontal'}>
@@ -250,7 +248,13 @@ const AddressInput = ({ setAddressCallback, currentWallet, addressValue, extraSe
250248
{
251249
displayDeleteButton
252250
? (
253-
<Button type='text' style={{ textAlign: 'left', height: '50px' }} onClick={() => deleteKnownAddress(address)}>
251+
<Button
252+
type='text' style={{ textAlign: 'left', height: '50px' }} onClick={(e) => {
253+
deleteKnownAddress(address)
254+
e.stopPropagation()
255+
return false
256+
}}
257+
>
254258
<CloseOutlined />
255259
</Button>
256260
)

code/client/src/constants/wallet.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ const ONEConstants = require('../../../lib/constants')
22
export default {
33
interval: 30 * 1000,
44
defaultDuration: 3600 * 1000 * 24 * 364,
5-
defaultDailyLimit: 1000, // ONEs
5+
defaultSpendingLimit: 1000, // ONEs
6+
defaultSpendingInterval: ONEConstants.DefaultSpendingInterval,
67
minDuration: 3600 * 1000 * 24 * 120,
78
maxDuration: 3600 * 1000 * 24 * 364 * 2,
89
maxTransferAttempts: 3,

code/client/src/pages/Create.jsx

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ const sectionViews = {
130130
}
131131

132132
const Create = ({ advancedSetting }) => {
133+
// eslint-disable-next-line no-unused-vars
133134
const dev = useSelector(state => state.wallet.dev)
134135
const { isMobile, os } = useWindowDimensions()
135136
const dispatch = useDispatch()
@@ -163,7 +164,8 @@ const Create = ({ advancedSetting }) => {
163164
: oneWalletTreasurySelectOption
164165

165166
const [lastResortAddress, setLastResortAddress] = useState(defaultRecoveryAddress)
166-
const [dailyLimit, setDailyLimit] = useState(WalletConstants.defaultDailyLimit)
167+
const [spendingLimit, setSpendingLimit] = useState(WalletConstants.defaultSpendingLimit) // ONEs, number
168+
const [spendingInterval, setSpendingInterval] = useState(WalletConstants.defaultSpendingInterval) // seconds, number
167169

168170
const [worker, setWorker] = useState()
169171
const [root, setRoot] = useState()
@@ -282,7 +284,8 @@ const Create = ({ advancedSetting }) => {
282284
lifespan: duration / WalletConstants.interval,
283285
slotSize,
284286
lastResortAddress: normalizedAddress,
285-
dailyLimit: ONEUtil.toFraction(dailyLimit).toString()
287+
spendingLimit: ONEUtil.toFraction(spendingLimit).toString(),
288+
spendingInterval,
286289
})
287290
// console.log('Deployed. Received contract address', address)
288291
const wallet = {
@@ -293,11 +296,15 @@ const Create = ({ advancedSetting }) => {
293296
slotSize,
294297
effectiveTime,
295298
lastResortAddress: normalizedAddress,
296-
dailyLimit: ONEUtil.toFraction(dailyLimit).toString(),
299+
spendingLimit: ONEUtil.toFraction(spendingLimit).toString(),
297300
hseed: ONEUtil.hexView(hseed),
301+
spendingInterval: spendingInterval * 1000,
302+
majorVersion: ONEConstants.MajorVersion,
303+
minorVersion: ONEConstants.MinorVersion,
298304
network,
299305
doubleOtp,
300306
...securityParameters,
307+
expert: !!advancedSetting,
301308
}
302309
await storeLayers()
303310
dispatch(walletActions.updateWallet(wallet))
@@ -431,11 +438,23 @@ const Create = ({ advancedSetting }) => {
431438
{advancedSetting &&
432439
<Row style={{ marginBottom: 16 }}>
433440
<Space direction='vertical' size='small'>
434-
<Hint>Set up a daily spending limit:</Hint>
435-
<InputBox
436-
margin={16} width={200} value={dailyLimit}
437-
onChange={({ target: { value } }) => setDailyLimit(parseInt(value || 0))} suffix='ONE'
438-
/>
441+
<Hint>Set up a spending limit:</Hint>
442+
<Space align='baseline'>
443+
<InputBox
444+
margin={16} width={160} value={spendingLimit}
445+
onChange={({ target: { value } }) => setSpendingLimit(parseInt(value || 0))} suffix='ONE'
446+
/>
447+
<Hint>per</Hint>
448+
<InputBox
449+
margin={16} width={128} value={spendingInterval}
450+
onChange={({ target: { value } }) => setSpendingInterval(parseInt(value || 0))}
451+
/>
452+
<Hint>seconds</Hint>
453+
</Space>
454+
<Row justify='end'>
455+
<Hint>{humanizeDuration(spendingInterval * 1000, { largest: 2, round: true })}</Hint>
456+
</Row>
457+
439458
</Space>
440459
</Row>}
441460
<Row style={{ marginBottom: 48 }}>
@@ -491,7 +510,7 @@ const Create = ({ advancedSetting }) => {
491510
<Space direction='vertical'>
492511
<Hint>No private key. No mnemonic. Simple and Secure. </Hint>
493512
<Hint>To learn more, visit <Link href='https://github.com/polymorpher/one-wallet/wiki'>1wallet Wiki</Link></Hint>
494-
<Hint>In Beta, your wallet is subject to a daily spending limit of {WalletConstants.defaultDailyLimit} ONE</Hint>
513+
<Hint>In Beta, your wallet is subject to a daily spending limit of {WalletConstants.defaultSpendingLimit} ONE</Hint>
495514
</Space>
496515
</Row>
497516
</AnimatedSection>

0 commit comments

Comments
 (0)