-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(mobile): Swap domain with app name in TonConnectModal (#683)
* fix(mobile): Swap domain with app name in TonConnectModal * fix(mobile): Add typings
- Loading branch information
1 parent
09ca445
commit 1d656c2
Showing
8 changed files
with
59 additions
and
8 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { isString } from '@tonkeeper/uikit'; | ||
import React from 'react'; | ||
|
||
let escapeRegExp = function escapeRegExp(str: string) { | ||
let reRegExpChar = /[\\^$.*+?()[\]{}|]/g, | ||
reHasRegExpChar = RegExp(reRegExpChar.source); | ||
|
||
return str && reHasRegExpChar.test(str) ? str.replace(reRegExpChar, '\\$&') : str; | ||
}; | ||
|
||
export function replaceString( | ||
str: string, | ||
match: string, | ||
fn: (str: string, i: number, c: number) => React.ReactNode, | ||
): React.ReactNode[] | React.ReactNode { | ||
let curCharStart = 0; | ||
let curCharLen = 0; | ||
|
||
if (str === '') { | ||
return str; | ||
} else if (!str || !isString(str)) { | ||
throw new TypeError( | ||
'First argument to react-string-replace#replaceString must be a string', | ||
); | ||
} | ||
|
||
let re = new RegExp('(' + escapeRegExp(match) + ')', 'gi'); | ||
|
||
let matches: undefined | string[] = str.split(re); | ||
let toReturn: React.ReactNode = matches; | ||
|
||
for (let i = 1, length = matches.length; i < length; i += 2) { | ||
if (matches[i] === undefined || matches[i - 1] === undefined) { | ||
console.warn('Encountered undefined value during string replacement'); | ||
continue; | ||
} | ||
|
||
curCharLen = matches[i].length; | ||
curCharStart += matches[i - 1].length; | ||
toReturn[i] = fn(matches[i], i, curCharStart); | ||
curCharStart += curCharLen; | ||
} | ||
|
||
return toReturn; | ||
} |