-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/eslint/disable-logs
- Loading branch information
Showing
9 changed files
with
298 additions
and
123 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
142 changes: 59 additions & 83 deletions
142
client/src/app/components/stardust/block/payload/TransactionPayload.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 |
---|---|---|
@@ -1,104 +1,80 @@ | ||
import React, { ReactNode } from "react"; | ||
import { TransactionPayloadProps } from "./TransactionPayloadProps"; | ||
import { TransactionPayloadState } from "./TransactionPayloadState"; | ||
import React, { useContext, useEffect, useState } from "react"; | ||
import NetworkContext from "~/app/context/NetworkContext"; | ||
import transactionPayloadMessage from "~assets/modals/stardust/block/transaction-payload.json"; | ||
import NetworkContext from "../../../../context/NetworkContext"; | ||
import AsyncComponent from "../../../AsyncComponent"; | ||
import { getInputsPreExpandedConfig, getOutputsPreExpandedConfig } from "~helpers/stardust/preExpandedConfig"; | ||
import { IPreExpandedConfig } from "~models/components"; | ||
import Modal from "../../../Modal"; | ||
import Input from "../../Input"; | ||
import Output from "../../Output"; | ||
import Unlocks from "../../Unlocks"; | ||
import "./TransactionPayload.scss"; | ||
import { TransactionPayloadProps } from "./TransactionPayloadProps"; | ||
|
||
/** | ||
* Component which will display a transaction payload. | ||
*/ | ||
class TransactionPayload extends AsyncComponent<TransactionPayloadProps, TransactionPayloadState> { | ||
/** | ||
* The component context type. | ||
*/ | ||
public static contextType = NetworkContext; | ||
|
||
/** | ||
* The component context. | ||
*/ | ||
public declare context: React.ContextType<typeof NetworkContext>; | ||
|
||
/** | ||
* Create a new instance of TransactionPayload. | ||
* @param props The props. | ||
*/ | ||
constructor(props: TransactionPayloadProps) { | ||
super(props); | ||
|
||
this.state = { | ||
isFormattedBalance: true, | ||
}; | ||
} | ||
const TransactionPayload: React.FC<TransactionPayloadProps> = ({ network, inputs, unlocks, outputs, header, isLinksDisabled }) => { | ||
const [inputsPreExpandedConfig, setInputsPreExpandedConfig] = useState<IPreExpandedConfig[]>([]); | ||
const { bech32Hrp } = useContext(NetworkContext); | ||
|
||
/** | ||
* The component mounted. | ||
*/ | ||
public async componentDidMount(): Promise<void> { | ||
super.componentDidMount(); | ||
} | ||
const outputsPreExpandedConfig = getOutputsPreExpandedConfig(outputs); | ||
|
||
/** | ||
* Render the component. | ||
* @returns The node to render. | ||
*/ | ||
public render(): ReactNode { | ||
const { network, inputs, unlocks, outputs, header, isLinksDisabled } = this.props; | ||
useEffect(() => { | ||
if (bech32Hrp) { | ||
const inputsPreExpandedConfig = getInputsPreExpandedConfig(inputs, unlocks, bech32Hrp); | ||
setInputsPreExpandedConfig(inputsPreExpandedConfig); | ||
} | ||
}, [bech32Hrp]); | ||
|
||
return ( | ||
<div className="transaction-payload"> | ||
{header && ( | ||
<div className="section--header"> | ||
<div className="row middle"> | ||
<h2>{header}</h2> | ||
<Modal icon="info" data={transactionPayloadMessage} /> | ||
</div> | ||
return ( | ||
<div className="transaction-payload"> | ||
{header && ( | ||
<div className="section--header"> | ||
<div className="row middle"> | ||
<h2>{header}</h2> | ||
<Modal icon="info" data={transactionPayloadMessage} /> | ||
</div> | ||
)} | ||
<div className="row row--tablet-responsive fill"> | ||
<div className="card col fill"> | ||
<div className="card--header"> | ||
<h2 className="card--header__title">From</h2> | ||
<span className="dot-separator">•</span> | ||
<span>{inputs.length}</span> | ||
</div> | ||
<div className="transaction-payload_outputs card--content"> | ||
{inputs.map((input, idx) => ( | ||
<Input key={idx} network={network} input={input} /> | ||
))} | ||
<Unlocks unlocks={unlocks} /> | ||
</div> | ||
</div> | ||
)} | ||
<div className="row row--tablet-responsive fill"> | ||
<div className="card col fill"> | ||
<div className="card--header"> | ||
<h2 className="card--header__title">From</h2> | ||
<span className="dot-separator">•</span> | ||
<span>{inputs.length}</span> | ||
</div> | ||
<div className="transaction-payload_outputs card--content"> | ||
{inputs.map((input, idx) => ( | ||
<Input key={idx} network={network} input={input} preExpandedConfig={inputsPreExpandedConfig[idx]} /> | ||
))} | ||
<Unlocks unlocks={unlocks} /> | ||
</div> | ||
</div> | ||
|
||
<div className="card col fill"> | ||
<div className="card--header"> | ||
<h2 className="card--header__title">To</h2> | ||
<span className="dot-separator">•</span> | ||
<span>{outputs.length}</span> | ||
</div> | ||
<div className="transaction-payload_outputs card--content"> | ||
{outputs.map((output, idx) => ( | ||
<Output | ||
key={idx} | ||
outputId={output.id} | ||
output={output.output} | ||
amount={output.amount} | ||
network={network} | ||
showCopyAmount={true} | ||
isLinksDisabled={isLinksDisabled} | ||
/> | ||
))} | ||
</div> | ||
<div className="card col fill"> | ||
<div className="card--header"> | ||
<h2 className="card--header__title">To</h2> | ||
<span className="dot-separator">•</span> | ||
<span>{outputs.length}</span> | ||
</div> | ||
<div className="transaction-payload_outputs card--content"> | ||
{outputs.map((output, idx) => ( | ||
<Output | ||
key={idx} | ||
outputId={output.id} | ||
output={output.output} | ||
amount={output.amount} | ||
network={network} | ||
showCopyAmount={true} | ||
isLinksDisabled={isLinksDisabled} | ||
preExpandedConfig={outputsPreExpandedConfig[idx]} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
</div> | ||
); | ||
}; | ||
|
||
export default TransactionPayload; |
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.