-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Centrifuge App: Convert EVM address to Subtrate (#1532)
- Loading branch information
1 parent
38c9883
commit 7606648
Showing
3 changed files
with
43 additions
and
0 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
25 changes: 25 additions & 0 deletions
25
centrifuge-app/src/components/DebugFlags/components/ConvertEvmAddress.tsx
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,25 @@ | ||
import { evmToSubstrateAddress } from '@centrifuge/centrifuge-js' | ||
import { useCentrifuge, useWallet } from '@centrifuge/centrifuge-react' | ||
import { isAddress } from '@ethersproject/address' | ||
|
||
export function ConvertEvmAddress() { | ||
const ctx = useWallet() | ||
const cent = useCentrifuge() | ||
function convert() { | ||
const addr = window.prompt('EVM address') | ||
if (!addr || !isAddress(addr)) { | ||
window.alert('Invalid EVM address') | ||
return | ||
} | ||
const chainId = window.prompt('Chain ID', String(ctx.substrate.evmChainId)) | ||
if (!chainId || !Number.isSafeInteger(Number(chainId))) { | ||
window.alert('Invalid chain ID') | ||
return | ||
} | ||
const converted = evmToSubstrateAddress(addr, Number(chainId)) | ||
const formatted = cent.utils.formatAddress(converted) | ||
window.alert(formatted) | ||
console.log('Substrate address', formatted) | ||
} | ||
return <button onClick={convert}>Convert EVM to Substrate</button> | ||
} |
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