-
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
feat: import transactions from Safe builder #147
Closed
gsteenkamp89
wants to merge
28
commits into
master
from
gerhard/uma-2431-figure-out-how-to-get-safe-transactions-into-snapshot-osnap
Closed
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
a49f928
feat: allow safe json upload into osnap tx builder
daywiss 6217d74
parse batchfile & populate input fields with values
gsteenkamp89 2f48613
show value & to fields
gsteenkamp89 fad35f7
improve input
gsteenkamp89 81e396b
improve file input error handling and styling
gsteenkamp89 cff8986
refactor
gsteenkamp89 4dca2b7
refactor
gsteenkamp89 928fb22
minor bug fix
gsteenkamp89 22e1678
allow quick fix for short bytes32
gsteenkamp89 bc81130
align icon better
gsteenkamp89 395d4c0
make file input own component
gsteenkamp89 dfb2406
import file once and initialize multiple safeImport transactions
gsteenkamp89 7cb56ed
check if safe address & chainId match
gsteenkamp89 4dfee57
small fixes
gsteenkamp89 b3d41e7
clean up comments
gsteenkamp89 877053e
better border sie for file input
gsteenkamp89 75699bf
clear input element value to allow recurring upload
gsteenkamp89 83203a8
fix quick fix
gsteenkamp89 7246ebb
handle multiple files
gsteenkamp89 b81907f
better error message
gsteenkamp89 568289c
emit from watcher
gsteenkamp89 23091f1
Merge branch 'master' into gerhard/uma-2431-figure-out-how-to-get-saf…
gsteenkamp89 625fcf8
fix: use upstream state only
gsteenkamp89 da49507
clean up
gsteenkamp89 8bf005c
do byteslike check last
gsteenkamp89 7f5adef
fixes
gsteenkamp89 728e26e
add default label
gsteenkamp89 529e427
fix: remove component level tx state
gsteenkamp89 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
125 changes: 125 additions & 0 deletions
125
src/plugins/oSnap/components/Input/FileInput/FileInput.vue
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,125 @@ | ||
<script setup lang="ts"> | ||
import { ref, defineProps, watch } from 'vue'; | ||
import { getFilesFromEvent, isFileOfType } from './utils'; | ||
|
||
type InputState = 'IDLE' | 'INVALID_TYPE' | 'VALID' | 'INVALID_QUANTITY'; | ||
|
||
const props = defineProps<{ | ||
fileType: File['type']; | ||
error?: string | undefined; | ||
multiple?: boolean; | ||
}>(); | ||
|
||
const emit = defineEmits<{ | ||
(event: 'update:file', file: File | null): void; | ||
(event: 'update:fileInputState', state: InputState): void; | ||
}>(); | ||
const inputRef = ref<HTMLInputElement>(); | ||
const file = ref<File | null>(); | ||
const fileInputState = ref<InputState>('IDLE'); | ||
const isDropping = ref(false); | ||
|
||
const isError = computed(() => { | ||
return ( | ||
!!props.error || | ||
fileInputState.value === 'INVALID_TYPE' || | ||
fileInputState.value === 'INVALID_QUANTITY' | ||
); | ||
}); | ||
|
||
const isAccepted = computed(() => { | ||
return fileInputState.value === 'VALID' && !props?.error; | ||
}); | ||
|
||
const handleFileChange = (event: Event | DragEvent) => { | ||
isDropping.value = false; | ||
const _files = getFilesFromEvent(event); | ||
if (!_files?.length) return; | ||
|
||
// enforce single drop based on props | ||
if (!props.multiple) { | ||
if (_files?.length && _files?.length > 1) { | ||
fileInputState.value = 'INVALID_QUANTITY'; | ||
file.value = null; | ||
clearInputValue(); | ||
return; | ||
} | ||
} | ||
const _file = _files[0]; | ||
if (!isFileOfType(_file, props.fileType)) { | ||
fileInputState.value = 'INVALID_TYPE'; | ||
file.value = null; | ||
} else { | ||
file.value = _file; | ||
fileInputState.value = 'VALID'; | ||
} | ||
clearInputValue(); | ||
}; | ||
|
||
function clearInputValue() { | ||
if (inputRef?.value) { | ||
inputRef.value.value = ''; | ||
} | ||
} | ||
|
||
function toggleDropping() { | ||
isDropping.value = !isDropping.value; | ||
} | ||
|
||
watch(file, newFile => { | ||
if (newFile) { | ||
emit('update:file', newFile); | ||
} | ||
}); | ||
|
||
watch(fileInputState, newState => { | ||
emit('update:fileInputState', newState); | ||
}); | ||
</script> | ||
|
||
<template> | ||
<label | ||
for="file_input" | ||
@dragenter.prevent="toggleDropping" | ||
@dragleave.prevent="toggleDropping" | ||
@dragover.prevent | ||
@drop.prevent="handleFileChange($event)" | ||
class="my-2 w-full group hover:bg-transparent hover:border-skin-text hover:text-skin-link hover:cursor-pointer inline-block border-2 border-dashed py-2 px-4 rounded-xl" | ||
:class="{ | ||
'border-solid border-skin-text text-skin-link bg-transparent': isDropping, | ||
'bg-red/10 border-red/50 text-red/80': isError, | ||
'bg-green/10 border-green/50 text-green/80': isAccepted | ||
}" | ||
> | ||
<div | ||
class="flex line-clamp-2 flex-col gap-1 items-center text-center justify-center" | ||
> | ||
<i-ho-upload /> | ||
<span class="line-clamp-2"> | ||
<template v-if="props.error">{{ props.error }}</template> | ||
<template v-else-if="fileInputState === 'INVALID_TYPE'" | ||
>File type must be <strong>{{ props.fileType }}</strong | ||
>. Please choose another.</template | ||
> | ||
<template v-else-if="fileInputState === 'INVALID_QUANTITY'" | ||
>Drop only <strong class="underline">one</strong> file at a time | ||
</template> | ||
<template v-else-if="fileInputState === 'VALID' && file">{{ | ||
file.name | ||
}}</template> | ||
<template v-else="fileInputState === 'IDLE'" | ||
>Click to select file, or drag n drop</template | ||
> | ||
</span> | ||
</div> | ||
|
||
<input | ||
ref="inputRef" | ||
id="file_input" | ||
class="hidden" | ||
:accept="props.fileType" | ||
type="file" | ||
@change="handleFileChange" | ||
/> | ||
</label> | ||
</template> |
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,17 @@ | ||
export function isFileOfType(file: File, type: File['type']) { | ||
return file.type === type; | ||
} | ||
|
||
export function getFilesFromEvent(event: DragEvent | Event) { | ||
let _files: FileList | undefined | null; | ||
|
||
if (event instanceof DragEvent) { | ||
_files = event.dataTransfer?.files; | ||
} | ||
|
||
if (event.target && event.target instanceof HTMLInputElement) { | ||
_files = (event?.currentTarget as HTMLInputElement)?.files; | ||
} | ||
if (!_files) return; | ||
return _files; | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this check should be done last. i think it should either be in this order, too short, too long, isBytesLIke
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.
fixed