-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add signature for structured data
closes #2387
- Loading branch information
1 parent
ef217be
commit 17591a2
Showing
14 changed files
with
362 additions
and
42 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
76 changes: 76 additions & 0 deletions
76
src/app/pages/signature-request/components/ClarityValueListComponent.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,76 @@ | ||
import { ClarityType, ClarityValue, cvToString } from '@stacks/transactions'; | ||
import { principalToString } from '@stacks/transactions/dist/esm/clarity/types/principalCV'; | ||
|
||
export function ClarityValueListComponent(props: { | ||
val: ClarityValue; | ||
encoding?: 'tryAscii' | 'hex'; | ||
isRoot?: boolean; | ||
}): JSX.Element { | ||
const { val, encoding, isRoot = true } = props; | ||
|
||
function wrapText(text: string): JSX.Element { | ||
return <>{text}</>; | ||
} | ||
switch (val.type) { | ||
case ClarityType.BoolTrue: | ||
return wrapText('true'); | ||
case ClarityType.BoolFalse: | ||
return wrapText('false'); | ||
case ClarityType.Int: | ||
return wrapText(val.value.toString()); | ||
case ClarityType.UInt: | ||
return wrapText(`u${val.value.toString()}`); | ||
case ClarityType.Buffer: | ||
if (encoding === 'tryAscii') { | ||
const str = val.buffer.toString('ascii'); | ||
if (/[ -~]/.test(str)) { | ||
return wrapText(JSON.stringify(str)); | ||
} | ||
} | ||
return wrapText(`0x${val.buffer.toString('hex')}`); | ||
case ClarityType.OptionalNone: | ||
return wrapText('none'); | ||
case ClarityType.OptionalSome: | ||
return wrapText(`some ${cvToString(val.value, encoding)}`); | ||
case ClarityType.ResponseErr: | ||
return wrapText(`err ${cvToString(val.value, encoding)}`); | ||
case ClarityType.ResponseOk: | ||
return wrapText(`ok ${cvToString(val.value, encoding)}`); | ||
case ClarityType.PrincipalStandard: | ||
case ClarityType.PrincipalContract: | ||
return wrapText(principalToString(val)); | ||
case ClarityType.List: | ||
return wrapText(`[${val.list.map(v => cvToString(v, encoding)).join(', ')}]`); | ||
case ClarityType.Tuple: | ||
return ( | ||
<dl | ||
style={{ | ||
display: 'flex', | ||
flexFlow: 'row', | ||
flexWrap: 'wrap', | ||
paddingTop: isRoot ? '0' : '20px', | ||
overflow: 'visible', | ||
}} | ||
> | ||
{Object.keys(val.data).map(key => { | ||
return ( | ||
<> | ||
<dt style={{ flex: '0 0 20%', color: '#74777D' }}>{key}:</dt> | ||
<dd style={{ flex: '0 0 80%' }}> | ||
<ClarityValueListComponent | ||
val={val.data[key]} | ||
encoding={'tryAscii'} | ||
isRoot={false} | ||
/> | ||
</dd> | ||
</> | ||
); | ||
})} | ||
</dl> | ||
); | ||
case ClarityType.StringASCII: | ||
return wrapText(`"${val.data}"`); | ||
case ClarityType.StringUTF8: | ||
return wrapText(`u"${val.data}"`); | ||
} | ||
} |
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
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.