Nethereum / Nethereum.Playground

Compile and run Nethereum snippets on the browser
MIT License
28 stars 17 forks source link

Add file picker to load abi and bytecode #18

Closed juanfranblanco closed 5 years ago

juanfranblanco commented 5 years ago

As per suggestion, addition of file picker for abi and bytecode

This is what is required (more or less) @Dave-Whiffin In the AbiCodeGenerateBase model put

public ElementReference ABIFileUpload { get; set; }
public ElementReference ByteCodeFileUpload { get; set; }
 public async Task ReadFileABI()
        {
            var files = await FileReaderService.CreateReference(ABIFileUpload).EnumerateFilesAsync();
            var stream = await files.First().CreateMemoryStreamAsync(); 
            var streamReader = new System.IO.StreamReader(stream);
            Model.Abi = streamReader.ReadToEnd();
        }

 public async Task ReadFileByteCode()
        {
            var files = await FileReaderService.CreateReference(ByteCodeFileUpload).EnumerateFilesAsync();
            var stream = await files.First().CreateMemoryStreamAsync(); 
            var streamReader = new System.IO.StreamReader(stream);
            Model.ByteCode = streamReader.ReadToEnd();
        }

On the Razor file pug

<input type="file" class="btn btn-primary" @ref="@ABIFileUpload " @ref:suppressField @onchange="@ReadFileABI" />

<input type="file" class="btn btn-primary" @ref="@ByteCodeFileUpload  " @ref:suppressField @onchange="@ReadFileByteCode" />
juanfranblanco commented 5 years ago

Done in pull #20