Skip to content

Commit

Permalink
feat: handle sign button instead of needs sig
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomariscal committed Jul 8, 2024
1 parent 44c53b3 commit a211d46
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
51 changes: 40 additions & 11 deletions frontend/src/components/WithdrawForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
<base-input
v-model="content"
@update:modelValue="emitUpdateDestinationAddress"
@click="
emit('initializeWithdraw');
setIsInWithdrawFlow(true);
"
@click="handleSubmit"
:appendButtonLabel="needSignature ? $t('WithdrawForm.need-signature') : $t('WithdrawForm.withdraw')"
:appendButtonDisable="isInWithdrawFlow || isFeeLoading || needSignature"
:appendButtonDisable="isInWithdrawFlow || isFeeLoading || isSigningInProgress"
:appendButtonLoading="isInWithdrawFlow"
:disable="isInWithdrawFlow"
:label="$t('WithdrawForm.address')"
lazy-rules
:rules="(val) => (val && val.length > 4) || $t('WithdrawForm.enter-valid-address')"
:rules="(val: string | null) => (val && val.length > 4) || $t('WithdrawForm.enter-valid-address')"
/>
<!-- Fee estimate -->
<div class="q-mb-lg">
Expand Down Expand Up @@ -123,25 +120,57 @@ export default defineComponent({
},
},
setup(data, { emit }) {
const { NATIVE_TOKEN } = useWalletStore();
const { NATIVE_TOKEN, getPrivateKeys } = useWalletStore();
const { setIsInWithdrawFlow, isInWithdrawFlow } = useStatusesStore();
const { needSignature } = useWalletStore();
const content = ref<string>(data.destinationAddress || '');
const nativeTokenSymbol = NATIVE_TOKEN.value.symbol;
const isSigningInProgress = ref(false);
function emitUpdateDestinationAddress(val: string) {
emit('updateDestinationAddress', val);
}
function initializeWithdraw() {
// Simple validation
if (!content.value || content.value.length <= 4) return;
emit('initializeWithdraw');
setIsInWithdrawFlow(true);
}
async function handleSubmit() {
if (needSignature.value) {
try {
isSigningInProgress.value = true;
const success = await getPrivateKeys();
if (success === 'denied') {
console.log('User denied signature request');
isSigningInProgress.value = false;
return;
}
initializeWithdraw();
} catch (error) {
console.error('Error getting private keys:', error);
} finally {
isSigningInProgress.value = false;
}
} else {
initializeWithdraw();
}
}
return {
formatUnits,
humanizeTokenAmount,
content,
emit,
emitUpdateDestinationAddress,
content,
formatUnits,
handleSubmit,
humanizeTokenAmount,
isInWithdrawFlow,
isSigningInProgress,
nativeTokenSymbol,
needSignature,
isInWithdrawFlow,
setIsInWithdrawFlow,
};
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@
"view-on-explorer": "View on explorer"
},
"WithdrawForm": {
"need-signature": "Need Signature",
"need-signature": "Sign",
"withdraw-address": "Enter address to withdraw funds to",
"address": "Address",
"fetching-fee-estimate": "Fetching fee estimate...",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@
"view-on-explorer": "在区块链浏览器上查看"
},
"WithdrawForm": {
"need-signature": "此应用程序需要您的签名才能扫描您收到的资金",
"need-signature": "签名",
"withdraw-address": "输入提款地址",
"address": "地址",
"fetching-fee-estimate": "在接收费用估计...",
Expand Down

0 comments on commit a211d46

Please sign in to comment.