-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Work on ledger notification * Converted nativeAuth ttl seconds to time string * push unlinked yarn.lock * changed UI nativeAuth description * updated CHANGELOG.md * - * updated ledger UI confirm screen only for ledger with usernames feature * fix double login with providers (#912) * fix double login with providers * regenerate yarn lock * reset version * 2.20.1 * changelog * resolved comments * put back version * resolved comments * update readme * update readme * Ag fix transaction cancel (#915) * fix transaction cancel * 2.20.2 * changelog * changelog * revert npm version * 2.20.2 --------- Co-authored-by: Tudor Morar <[email protected]> Co-authored-by: Theodor Dumitrache <[email protected]> Co-authored-by: Theodor Dumitrache <[email protected]> Co-authored-by: cipriandraghici <[email protected]>
- Loading branch information
1 parent
a34aba8
commit 20f669f
Showing
11 changed files
with
327 additions
and
175 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
45 changes: 45 additions & 0 deletions
45
src/UI/ledger/LedgerLoginContainer/ConfirmAddress/helpers/getAuthTokenText.ts
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,45 @@ | ||
import { decodeLoginToken } from 'services/nativeAuth/helpers/decodeLoginToken'; | ||
import getLedgerVersionOptions from 'utils/operations/ledger/getLedgerVersionOptions'; | ||
import { secondsToTimeString } from './secondsToTimeString'; | ||
|
||
export const getAuthTokenText = ({ | ||
loginToken, | ||
version | ||
}: { | ||
loginToken?: string; | ||
version?: string; | ||
}) => { | ||
if (!loginToken || !version) { | ||
return null; | ||
} | ||
|
||
const { ledgerWithUsernames } = getLedgerVersionOptions(version); | ||
const nativeAuthInfo = decodeLoginToken(loginToken); | ||
if (nativeAuthInfo == null) { | ||
return null; | ||
} | ||
|
||
const confirmAddressText = 'For security, please confirm that your address:'; | ||
const authText = 'and Auth Token:'; | ||
const areShownText = 'are the one shown on your Ledger device screen now.'; | ||
|
||
if (ledgerWithUsernames) { | ||
const time = secondsToTimeString(nativeAuthInfo.ttl); | ||
|
||
const confirmAddressText = 'For security, please confirm your address:'; | ||
const authText = 'and authorize:'; | ||
|
||
return { | ||
data: `${nativeAuthInfo.origin} for ${time}.`, | ||
confirmAddressText, | ||
authText | ||
}; | ||
} | ||
|
||
return { | ||
data: `${loginToken}{}`, | ||
confirmAddressText, | ||
authText, | ||
areShownText | ||
}; | ||
}; |
2 changes: 2 additions & 0 deletions
2
src/UI/ledger/LedgerLoginContainer/ConfirmAddress/helpers/index.ts
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,2 @@ | ||
export * from './getAuthTokenText'; | ||
export * from './secondsToTimeString'; |
29 changes: 29 additions & 0 deletions
29
src/UI/ledger/LedgerLoginContainer/ConfirmAddress/helpers/secondsToTimeString.ts
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,29 @@ | ||
import { isString } from 'lodash'; | ||
|
||
export const secondsToTimeString = (seconds: number) => { | ||
if (seconds <= 0 || isNaN(seconds) || !seconds || isString(seconds)) { | ||
return 'N/A time'; | ||
} | ||
|
||
if (seconds >= 86400) { | ||
return 'more than one day'; | ||
} | ||
|
||
const hours = Math.floor(seconds / 3600); | ||
const remainingSeconds = seconds % 3600; | ||
const minutes = Math.floor(remainingSeconds / 60); | ||
const remainingSecondsAfterMinutes = remainingSeconds % 60; | ||
|
||
const parts = []; | ||
if (hours > 0) { | ||
parts.push(`${hours}h`); | ||
} | ||
if (minutes > 0) { | ||
parts.push(`${minutes}min`); | ||
} | ||
if (remainingSecondsAfterMinutes > 0) { | ||
parts.push(`${remainingSecondsAfterMinutes}sec`); | ||
} | ||
|
||
return parts.join(' '); | ||
}; |
51 changes: 51 additions & 0 deletions
51
src/UI/ledger/LedgerLoginContainer/ConfirmAddress/helpers/tests/secondsToTimeString.test.ts
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,51 @@ | ||
import { secondsToTimeString } from '../secondsToTimeString'; | ||
|
||
describe('secondsToTimeString tests', () => { | ||
it('converts 0 seconds to "N/A time"', () => { | ||
expect(secondsToTimeString(0)).toBe('N/A time'); | ||
}); | ||
|
||
it('converts NaN to "N/A time"', () => { | ||
expect(secondsToTimeString(NaN)).toBe('N/A time'); | ||
}); | ||
|
||
it('converts undefined to "N/A time"', () => { | ||
expect(secondsToTimeString(undefined as any)).toBe('N/A time'); | ||
}); | ||
|
||
it('converts -1 to "N/A time"', () => { | ||
expect(secondsToTimeString(-1)).toBe('N/A time'); | ||
}); | ||
|
||
it('converts null to "N/A time"', () => { | ||
expect(secondsToTimeString(null as any)).toBe('N/A time'); | ||
}); | ||
|
||
it('converts string values to "N/A time"', () => { | ||
expect(secondsToTimeString('abc' as any)).toBe('N/A time'); | ||
expect(secondsToTimeString('123' as any)).toBe('N/A time'); | ||
}); | ||
|
||
it('converts seconds less than a minute correctly', () => { | ||
expect(secondsToTimeString(45)).toBe('45sec'); | ||
expect(secondsToTimeString(59)).toBe('59sec'); | ||
}); | ||
|
||
it('converts seconds to minutes and seconds correctly', () => { | ||
expect(secondsToTimeString(60)).toBe('1min'); | ||
expect(secondsToTimeString(123)).toBe('2min 3sec'); | ||
expect(secondsToTimeString(599)).toBe('9min 59sec'); | ||
}); | ||
|
||
it('converts seconds to hours, minutes, and seconds correctly', () => { | ||
expect(secondsToTimeString(3600)).toBe('1h'); | ||
expect(secondsToTimeString(3666)).toBe('1h 1min 6sec'); | ||
expect(secondsToTimeString(7200)).toBe('2h'); | ||
expect(secondsToTimeString(7323)).toBe('2h 2min 3sec'); | ||
}); | ||
|
||
it('handles more than 24 hours', () => { | ||
expect(secondsToTimeString(86400)).toBe('more than one day'); | ||
expect(secondsToTimeString(100000)).toBe('more than one day'); | ||
}); | ||
}); |
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
Oops, something went wrong.