-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5475 from LiskHQ/5473-fix-deeplinking-issue-to-se…
…nd-token Fix issue with balance validation on request token deep linking
- Loading branch information
Showing
11 changed files
with
120 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/modules/common/utils/getTokenBalanceErrorMessage.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { INSUFFICENT_TOKEN_BALANCE_MESSAGE } from '../constants'; | ||
import { getTokenBalanceErrorMessage } from './getTokenBalanceErrorMessage'; | ||
|
||
function interpolateFn(templateString, data) { | ||
let result = templateString; | ||
const keys = templateString.match(/{{[A-Za-z0-9_]+}}/g); | ||
keys.forEach((key) => { | ||
const normalizedKey = key.match(/(?<={{)[A-Za-z0-9_]+(?=}})/)?.[0]; | ||
|
||
if (normalizedKey && data[normalizedKey]) result = result.replace(key, data[normalizedKey]); | ||
}); | ||
|
||
return result; | ||
} | ||
|
||
describe('getTokenBalanceErrorMessage', () => { | ||
const mockTranslationFn = jest.fn((text, data) => interpolateFn(text, data)); | ||
|
||
it('Should not return an error message', () => { | ||
const result = getTokenBalanceErrorMessage({ | ||
t: mockTranslationFn, | ||
hasAvailableTokenBalance: true, | ||
hasSufficientBalanceForFee: true, | ||
feeTokenSymbol: 'LSK', | ||
}); | ||
|
||
expect(result).toEqual({}); | ||
}); | ||
it('Should return an insufficient fee error message', () => { | ||
const result = getTokenBalanceErrorMessage({ | ||
t: mockTranslationFn, | ||
hasAvailableTokenBalance: true, | ||
hasSufficientBalanceForFee: false, | ||
feeTokenSymbol: 'LSK', | ||
}); | ||
|
||
expect(result).toEqual({ | ||
message: 'There are no LSK tokens to pay for fees.', | ||
}); | ||
}); | ||
it('Should return an insufficent token balance error message if error type is provided', () => { | ||
const result = getTokenBalanceErrorMessage({ | ||
t: mockTranslationFn, | ||
hasAvailableTokenBalance: false, | ||
hasSufficientBalanceForFee: false, | ||
feeTokenSymbol: 'LSK', | ||
errorType: 'registerValidator', | ||
}); | ||
|
||
expect(result).toEqual({ | ||
message: INSUFFICENT_TOKEN_BALANCE_MESSAGE.registerValidator, | ||
}); | ||
}); | ||
|
||
it('Should return an insufficent token balance error message if error type is not provided', () => { | ||
const result = getTokenBalanceErrorMessage({ | ||
t: mockTranslationFn, | ||
hasAvailableTokenBalance: false, | ||
hasSufficientBalanceForFee: false, | ||
feeTokenSymbol: 'LSK', | ||
}); | ||
|
||
expect(result).toEqual({ | ||
message: INSUFFICENT_TOKEN_BALANCE_MESSAGE.sendToken, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters