Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Bug) #1052 Prevent to run multiple transaction #1053

Merged
merged 8 commits into from
Dec 18, 2019
15 changes: 15 additions & 0 deletions src/components/appNavigation/__tests__/NavBar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'
import renderer from 'react-test-renderer'
import NavBar from '../NavBar'

describe('NavBar', () => {
it('renders without errors', () => {
const tree = renderer.create(<NavBar />)
expect(tree.toJSON()).toBeTruthy()
})

it('matches snapshot', () => {
const component = renderer.create(<NavBar />)
expect(component.toJSON()).toMatchSnapshot()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`NavBar matches snapshot 1`] = `
<div
className="css-view-1dbjc4n"
style={
Object {
"WebkitAlignItems": "center",
"WebkitBoxAlign": "center",
"WebkitBoxDirection": "normal",
"WebkitBoxFlex": 0,
"WebkitBoxOrient": "horizontal",
"WebkitFlexDirection": "row",
"WebkitFlexGrow": 0,
"WebkitFlexShrink": 0,
"alignItems": "center",
"backgroundColor": "rgba(98,0,238,1.00)",
"boxShadow": "none, 0px 3px 4px rgba(0,0,0,0.24)",
"flexDirection": "row",
"flexGrow": 0,
"flexShrink": 0,
"height": "56px",
"msFlexAlign": "center",
"msFlexDirection": "row",
"msFlexNegative": 0,
"msFlexPositive": 0,
"paddingLeft": "4px",
"paddingRight": "4px",
}
}
>
<div
className="css-view-1dbjc4n"
data-focusable={true}
onKeyDown={[Function]}
onKeyUp={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Object {
"WebkitBoxFlex": 1,
"WebkitFlexBasis": "0%",
"WebkitFlexGrow": 1,
"WebkitFlexShrink": 1,
"cursor": "pointer",
"flexBasis": "0%",
"flexGrow": 1,
"flexShrink": 1,
"msFlexNegative": 1,
"msFlexPositive": 1,
"msFlexPreferredSize": "0%",
"msTouchAction": "manipulation",
"paddingLeft": "12px",
"paddingRight": "12px",
"touchAction": "manipulation",
}
}
tabIndex="0"
>
<h1
className="css-reset-4rbku5 css-text-901oao css-textOneLine-bfa6kz"
dir="auto"
role="heading"
style={
Object {
"color": "rgba(255,255,255,1.00)",
"direction": "ltr",
"fontFamily": "Roboto-Medium, Roboto, \\"Helvetica Neue\\", Helvetica, Arial, sans-serif",
"fontSize": "16px",
"fontWeight": "500",
"textAlign": "center",
"textTransform": "uppercase",
}
}
/>
</div>
</div>
`;
32 changes: 16 additions & 16 deletions src/components/dashboard/SendLinkSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,9 @@ const SendLinkSummary = ({ screenProps }: AmountProps) => {
let txHash

// Generate link deposit
const generateLinkResponse = goodWallet.generateLink(
amount,
reason,
({ paymentLink, code }) => (hash: string) => {
log.debug({ hash })
const generateLinkResponse = goodWallet.generateLink(amount, reason, {
onTransactionHash: hash => {
txHash = hash

// Save transaction
const transactionEvent: TransactionEvent = {
Expand All @@ -130,13 +128,17 @@ const SendLinkSummary = ({ screenProps }: AmountProps) => {
counterPartyDisplayName,
reason,
amount,
paymentLink,
code,
paymentLink: generateLinkResponse.paymentLink,
code: generateLinkResponse.code,
},
}

fireEvent('SEND_DONE', { type: 'link' })

log.debug('generateLinkAndSend: enqueueTX', { transactionEvent })

userStorage.enqueueTX(transactionEvent)

if (Config.isEToro) {
userStorage.saveSurveyDetails(hash, {
reason,
Expand All @@ -145,20 +147,18 @@ const SendLinkSummary = ({ screenProps }: AmountProps) => {
})
}
},
{
onTransactionHash: _h => {
txHash = _h
},
onError: () => {
userStorage.markWithErrorEvent(txHash)
},
}
)
onError: () => {
userStorage.markWithErrorEvent(txHash)
},
})

log.debug('generateLinkAndSend:', { generateLinkResponse })

if (generateLinkResponse) {
const { paymentLink } = generateLinkResponse
return paymentLink
}

showErrorDialog('Could not complete transaction. Please try again.')
} catch (e) {
showErrorDialog('Could not complete transaction. Please try again.')
Expand Down
8 changes: 6 additions & 2 deletions src/components/dashboard/SendQRSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const SendQRSummary = ({ screenProps }: AmountProps, params) => {
const faceRecognition = () => {
return screenProps.push('FRIntro', { from: 'SendQRSummary' })
}

const sendGD = () => {
try {
setLoading(true)
Expand Down Expand Up @@ -92,10 +93,15 @@ const SendQRSummary = ({ screenProps }: AmountProps, params) => {
buttons: [{ text: 'Yay!' }],
onDismiss: screenProps.goToRoot,
})

setLoading(false)

return hash
},
onError: e => {
log.error('Send TX failed:', e.message, e)

setLoading(false)
userStorage.markWithErrorEvent(txhash)
},
})
Expand All @@ -107,8 +113,6 @@ const SendQRSummary = ({ screenProps }: AmountProps, params) => {
message: `There was a problem sending G$. Try again`,
dismissText: 'OK',
})
} finally {
setLoading(false)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/dashboard/__tests__/SendQRSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import renderer from 'react-test-renderer'
import { getWebRouterComponentWithMocks } from './__util__'

describe('OutOfGasError', () => {
describe('SendQRSummary', () => {
it('renders without errors', () => {
const SendQRSummary = getWebRouterComponentWithMocks('../SendQRSummary')
let component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`OutOfGasError matches snapshot 1`] = `
exports[`SendQRSummary matches snapshot 1`] = `
<div
className="css-view-1dbjc4n"
style={
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React from 'react'
import renderer from 'react-test-renderer'
import { withThemeProvider } from '../../../__tests__/__util__'
import ViewAvatar from '../ViewOrUploadAvatar'
import ViewOrUploadAvatar from '../ViewOrUploadAvatar'

describe('ViewAvatar', () => {
const WrappedViewAvatar = withThemeProvider(ViewAvatar)
const WrappedViewOrUploadAvatar = withThemeProvider(ViewOrUploadAvatar)

it('renders without errors', () => {
const tree = renderer.create(<WrappedViewAvatar />)
const tree = renderer.create(<WrappedViewOrUploadAvatar />)
expect(tree.toJSON()).toBeTruthy()
})

it('matches snapshot', () => {
const component = renderer.create(<WrappedViewAvatar />)
const component = renderer.create(<WrappedViewOrUploadAvatar />)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
Expand Down
6 changes: 1 addition & 5 deletions src/lib/wallet/GoodWalletClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,6 @@ export class GoodWallet {
generateLink(
amount: number,
reason: string = '',
getOnTxHash: (extraData: { paymentLink: string, code: string }) => (hash: string) => any = () => () => {},
events: PromiEvents = defaultPromiEvents
): { code: string, hashedCode: string, paymentLink: string } {
const code = this.wallet.utils.randomHex(10).replace('0x', '')
Expand All @@ -559,10 +558,7 @@ export class GoodWallet {
reason,
})

//pass extra data
const onTransactionHash = getOnTxHash({ paymentLink, code })

const txPromise = this.depositToHash(amount, hashedCode, { ...events, onTransactionHash })
const txPromise = this.depositToHash(amount, hashedCode, events)

return {
code,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/wallet/__tests__/GoodWallet.fuse.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ describe('GoodWalletShare/ReceiveTokens', () => {
})

it('should deposit payment and withdraw', async () => {
const linkData = testWallet.generateLink(amount, reason, () => () => {})
const linkData = testWallet.generateLink(amount, reason)
expect(await linkData.txPromise).toBeTruthy()
expect(await testWallet2.withdraw(linkData.code)).toBeTruthy()
})

it('should deposit payment and cancel', async () => {
const linkData = testWallet.generateLink(amount, reason, () => () => {})
const linkData = testWallet.generateLink(amount, reason)
expect(await linkData.txPromise).toBeTruthy()
expect(await testWallet.cancelOTL(linkData.hashedCode)).toBeTruthy()
})
Expand Down Expand Up @@ -108,7 +108,7 @@ describe('GoodWalletShare/ReceiveTokens', () => {
it('should emit PaymentWithdraw and transfer event filtered by from block', async done => {
expect(await testWallet2.claim()).toBeTruthy()

const linkData = testWallet2.generateLink(amount, reason, () => () => {})
const linkData = testWallet2.generateLink(amount, reason)
expect(await linkData.txPromise.catch(_ => false)).toBeTruthy()
let eventId = testWallet2.subscribeToEvent('otplUpdated', receipt => {
expect(receipt).toBeTruthy()
Expand Down