-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: osnap improve how osnap form validates trarnsactions #123
Changes from 6 commits
ca54cad
15b7ca2
d4ab63c
a06b992
b6b1544
bb0bee9
b05164b
5e0bad0
c396625
707fdae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,15 +7,15 @@ import { ContractInteractionTransaction, Network } from '../../types'; | |
import { | ||
createContractInteractionTransaction, | ||
getABIWriteFunctions, | ||
getContractABI, | ||
validateTransaction | ||
getContractABI | ||
} from '../../utils'; | ||
import AddressInput from '../Input/Address.vue'; | ||
import MethodParameterInput from '../Input/MethodParameter.vue'; | ||
|
||
const props = defineProps<{ | ||
network: Network; | ||
transaction: ContractInteractionTransaction; | ||
setTransactionAsInvalid: () => void; | ||
}>(); | ||
|
||
const emit = defineEmits<{ | ||
|
@@ -24,7 +24,7 @@ const emit = defineEmits<{ | |
|
||
const to = ref(props.transaction.to ?? ''); | ||
const isToValid = computed(() => { | ||
return to.value === '' || isAddress(to.value); | ||
return to.value !== '' && isAddress(to.value); | ||
}); | ||
const abi = ref(props.transaction.abi ?? ''); | ||
const isAbiValid = ref(true); | ||
|
@@ -40,22 +40,27 @@ const selectedMethod = computed( | |
const parameters = ref<string[]>([]); | ||
|
||
function updateTransaction() { | ||
if (!isValueValid || !isToValid || !isAbiValid) return; | ||
try { | ||
if (!isToValid) { | ||
throw new Error('"TO" address invalid'); | ||
} | ||
if (!isAbiValid) { | ||
throw new Error('ABI invalid'); | ||
} | ||
if (!isValueValid) { | ||
throw new Error('Value invalid'); | ||
} | ||
// throws is method params are invalid | ||
const transaction = createContractInteractionTransaction({ | ||
to: to.value, | ||
value: value.value, | ||
abi: abi.value, | ||
method: selectedMethod.value, | ||
parameters: parameters.value | ||
}); | ||
|
||
if (validateTransaction(transaction)) { | ||
emit('updateTransaction', transaction); | ||
return; | ||
} | ||
} catch (error) { | ||
console.warn('ContractInteraction - Invalid Transaction:',error); | ||
emit('updateTransaction', transaction); | ||
} catch { | ||
props.setTransactionAsInvalid(); | ||
Comment on lines
+61
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is essentially what I'm doing in each transaction type. |
||
} | ||
} | ||
|
||
|
@@ -73,7 +78,7 @@ function updateMethod(methodName: string) { | |
function updateAbi(newAbi: string) { | ||
abi.value = newAbi; | ||
methods.value = []; | ||
|
||
updateTransaction(); | ||
try { | ||
methods.value = getABIWriteFunctions(abi.value); | ||
isAbiValid.value = true; | ||
|
@@ -82,26 +87,25 @@ function updateAbi(newAbi: string) { | |
isAbiValid.value = false; | ||
console.warn('error extracting useful methods', error); | ||
} | ||
updateTransaction(); | ||
} | ||
|
||
async function updateAddress() { | ||
updateTransaction(); | ||
const result = await getContractABI(props.network, to.value); | ||
if (result && result !== abi.value) { | ||
updateAbi(result); | ||
} | ||
updateTransaction(); | ||
} | ||
|
||
function updateValue(newValue: string) { | ||
value.value = newValue; | ||
updateTransaction(); | ||
try { | ||
parseAmount(newValue); | ||
isValueValid.value = true; | ||
} catch (error) { | ||
isValueValid.value = false; | ||
} | ||
updateTransaction(); | ||
} | ||
</script> | ||
|
||
|
@@ -137,8 +141,11 @@ function updateValue(newValue: string) { | |
</option> | ||
</UiSelect> | ||
|
||
<div v-if="selectedMethod && selectedMethod.inputs.length"> | ||
<div class="divider"></div> | ||
<div | ||
v-if="selectedMethod && selectedMethod.inputs.length" | ||
class="flex flex-col gap-2" | ||
> | ||
<div class="divider h-[1px] bg-skin-border my-3" /> | ||
|
||
<MethodParameterInput | ||
v-for="(input, index) in selectedMethod.inputs" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh i need to revert this change, since
value
should be allowed to be0