Skip to content

Commit

Permalink
[WEL-454] APTOS View Function Vector Parameter Error
Browse files Browse the repository at this point in the history
- change placeholder for type name
- change input format for vector<u8>
  • Loading branch information
kairoski03 committed Oct 23, 2023
1 parent bc3316f commit 2a80722
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/components/aptos/Compiler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,8 @@ export const Compiler: React.FunctionComponent<InterfaceProps> = ({
{estimatedGas ? (
<span style={{ fontWeight: 'bolder', fontSize: '1.1em' }}>
{' '}
( Estimated Gas {estimatedGas} )
( Estimated Gas {estimatedGas}. If the transaction fails, try again with a
higher gas fee.")
</span>
) : undefined}
</small>
Expand Down Expand Up @@ -1152,7 +1153,8 @@ export const Compiler: React.FunctionComponent<InterfaceProps> = ({
{entryEstimatedGas ? (
<span style={{ fontWeight: 'bolder', fontSize: '1.1em' }}>
{' '}
( Estimated Gas {entryEstimatedGas} )
( Estimated Gas {entryEstimatedGas}. If the transaction fails,
try again with a higher gas fee." )
</span>
) : undefined}
</small>
Expand Down
17 changes: 15 additions & 2 deletions src/components/aptos/EntryButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,27 @@ const EntryButton: React.FunctionComponent<Props> = ({

const entry = async (gasUnitPrice: string, maxGasAmount: string) => {
log.info('parameters', JSON.stringify(parameters, null, 2));
const refinedParameters = parameters.map((p) => {
if (p.type !== 'vector<u8>') {
return p;
}

return {
type: p.type,
val: Buffer.from(p.val, 'hex'),
};
});
log.info('refinedParameters', JSON.stringify(refinedParameters, null, 2));

const serializedArgs_ = serializedArgs(refinedParameters);
log.info('serializedArgs_', JSON.stringify(serializedArgs_, null, 2));
const dappTxn_ = await dappTxn(
accountId,
dapp.networks.aptos.chain,
atAddress + '::' + targetModule,
moveFunction?.name || '',
genericParameters.map((typeTag) => TxnBuilderTypes.StructTag.fromString(typeTag)),
serializedArgs(parameters),
serializedArgs_, // serializedArgs_,
dapp,
gasUnitPrice,
maxGasAmount,
Expand Down Expand Up @@ -114,8 +127,8 @@ const EntryButton: React.FunctionComponent<Props> = ({
dapp.networks.aptos.account.pubKey,
rawTransaction,
);
console.log(`estimatedGas${JSON.stringify(estimatedGas, null, 2)}`);

console.log(`@@@@@@@@@@@@@@@@@@@@`);
console.log(`gasRef.current=${JSON.stringify(gasRef.current, null, 2)}`);
setEntryEstimatedGas_(estimatedGas.gas_used);
setEntryGasUnitPrice_(estimatedGas.gas_unit_price);
Expand Down
16 changes: 14 additions & 2 deletions src/components/aptos/Parameters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const Parameters: React.FunctionComponent<InterfaceProps> = ({
</div>
<div>{func.params.length > 0 ? <small>Parameters</small> : <></>}</div>
{singerRemovedParams.map((parameterType: string, idx: number) => {
if (parameterType.startsWith('vector')) {
if (parameterType.startsWith('vector') && parameterType !== 'vector<u8>') {
return (
<VectorArgForm
func={func}
Expand All @@ -81,7 +81,7 @@ export const Parameters: React.FunctionComponent<InterfaceProps> = ({
className={'aptos-parameter'}
style={{ width: '100%', marginBottom: '5px' }}
type="text"
placeholder={parameterType}
placeholder={aptosParameterPlaceHolder(parameterType)}
size="sm"
onChange={(e) => {
updateParam(e.target.value, idx, parameterType);
Expand All @@ -92,3 +92,15 @@ export const Parameters: React.FunctionComponent<InterfaceProps> = ({
</div>
);
};

function aptosParameterPlaceHolder(parameterType: string) {
if (parameterType === 'vector<u8>') {
return `vector<u8> (ex. 616263)`;
}

if (parameterType === 'bool') {
return `bool (true / false)`;
}

return parameterType;
}
2 changes: 1 addition & 1 deletion src/components/aptos/aptos-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export const getEstimateGas = async (
});

const result = await response.json();
// console.log(`simulation result=${JSON.stringify(result, null, 2)}`);
console.log(`simulation result=${JSON.stringify(result, null, 2)}`);
return {
gas_unit_price: result[0].gas_unit_price,
max_gas_amount: result[0].max_gas_amount,
Expand Down

0 comments on commit 2a80722

Please sign in to comment.