This repository has been archived by the owner on May 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
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 #99 from darwinia-network/opaquecall
Opaquecall
- Loading branch information
Showing
7 changed files
with
153 additions
and
47 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
48 changes: 48 additions & 0 deletions
48
packages/react-components-darwinia/src/Params/OpaqueCall.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,48 @@ | ||
// Copyright 2017-2020 @polkadot/app-extrinsics authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
import { SubmittableExtrinsic } from '@polkadot/api/types'; | ||
import { Props, RawParam } from '@polkadot/react-params/types'; | ||
|
||
import React, { useCallback } from 'react'; | ||
import { useApi } from '@polkadot/react-hooks'; | ||
|
||
import ExtrinsicDisplay from './Extrinsic'; | ||
|
||
function OpaqueCall ({ className = '', isDisabled, isError, label, onChange, onEnter, onEscape, withLabel }: Props): React.ReactElement<Props> { | ||
const { apiDefaultTxSudo } = useApi(); | ||
|
||
const _onChange = useCallback( | ||
({ isValid, value }: RawParam): void => { | ||
let callData = null; | ||
|
||
if (isValid && value) { | ||
callData = (value as SubmittableExtrinsic<'promise'>).method.toHex(); | ||
} | ||
|
||
onChange && onChange({ | ||
isValid, | ||
value: callData | ||
}); | ||
}, | ||
[onChange] | ||
); | ||
|
||
return ( | ||
<ExtrinsicDisplay | ||
className={className} | ||
defaultValue={apiDefaultTxSudo} | ||
isDisabled={isDisabled} | ||
isError={isError} | ||
isPrivate | ||
label={label} | ||
onChange={_onChange} | ||
onEnter={onEnter} | ||
onEscape={onEscape} | ||
withLabel={withLabel} | ||
/> | ||
); | ||
} | ||
|
||
export default React.memo(OpaqueCall); |
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,48 @@ | ||
// Copyright 2017-2020 @polkadot/app-extrinsics authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
import { SubmittableExtrinsic } from '@polkadot/api/types'; | ||
import { Props, RawParam } from '@polkadot/react-params/types'; | ||
|
||
import React, { useCallback } from 'react'; | ||
import { useApi } from '@polkadot/react-hooks'; | ||
|
||
import ExtrinsicDisplay from './Extrinsic'; | ||
|
||
function OpaqueCall ({ className = '', isDisabled, isError, label, onChange, onEnter, onEscape, withLabel }: Props): React.ReactElement<Props> { | ||
const { apiDefaultTxSudo } = useApi(); | ||
|
||
const _onChange = useCallback( | ||
({ isValid, value }: RawParam): void => { | ||
let callData = null; | ||
|
||
if (isValid && value) { | ||
callData = (value as SubmittableExtrinsic<'promise'>).method.toHex(); | ||
} | ||
|
||
onChange && onChange({ | ||
isValid, | ||
value: callData | ||
}); | ||
}, | ||
[onChange] | ||
); | ||
|
||
return ( | ||
<ExtrinsicDisplay | ||
className={className} | ||
defaultValue={apiDefaultTxSudo} | ||
isDisabled={isDisabled} | ||
isError={isError} | ||
isPrivate | ||
label={label} | ||
onChange={_onChange} | ||
onEnter={onEnter} | ||
onEscape={onEscape} | ||
withLabel={withLabel} | ||
/> | ||
); | ||
} | ||
|
||
export default React.memo(OpaqueCall); |
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,31 @@ | ||
// Copyright 2017-2020 @polkadot/react-params authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
import { Props } from '../types'; | ||
|
||
import React from 'react'; | ||
import { registry } from '@polkadot/react-api'; | ||
import { Bytes } from '@polkadot/types'; | ||
|
||
import CallDisplay from './Call'; | ||
import Unknown from './Unknown'; | ||
|
||
function OpaqueCall (props: Props): React.ReactElement<Props> { | ||
if (!props.isDisabled) { | ||
return ( | ||
<Unknown {...props} /> | ||
); | ||
} | ||
|
||
const value = registry.createType('Call', (props.defaultValue.value as Bytes).toHex()); | ||
|
||
return ( | ||
<CallDisplay | ||
{...props} | ||
defaultValue={{ isValid: true, value }} | ||
/> | ||
); | ||
} | ||
|
||
export default React.memo(OpaqueCall); |
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