Skip to content

Commit

Permalink
Overhaul of Casing and OptionalValue<> changes (#13)
Browse files Browse the repository at this point in the history
* Initial

* Lots of Opt changes

* Initial

* Fixing naming

* Updating clients

* Update Index.razor

* Fixes

* Done for the night

* More

* More
  • Loading branch information
Gekctek committed Dec 30, 2022
1 parent 79fcff2 commit 3ecc1c2
Show file tree
Hide file tree
Showing 148 changed files with 3,391 additions and 2,968 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ IAgent agent = new HttpAgent(identity);
// Create Candid arg to send in request
ulong proposalId = 1234;
CandidArg arg = CandidArg.FromCandid(
CandidValueWithType.FromObject(proposalId)
CandidTypedValue.FromObject(proposalId)
);

// Make request to IC
Expand All @@ -41,7 +41,7 @@ QueryResponse response = await agent.QueryAsync(governanceCanisterId, method, ar

QueryReply reply = response.ThrowOrGetReply();
// Convert to custom class
ProposalInfo? info = reply.Arg.Values[0].ToObjectOrDefault<ProposalInfo>()
ProposalInfo? info = reply.Arg.Values[0].ToOptionalObject<ProposalInfo>()
```

## Usage (w/ Client Generator)
Expand Down Expand Up @@ -95,7 +95,7 @@ MyObj obj = new MyObj
Title = "Title 1",
IsGoodTitle = false
};
CandidValueWithType value = CandidValueWithType.FromObject(obj);
CandidTypedValue value = CandidTypedValue.FromObject(obj);
```
## Parse from Text
```cs
Expand Down
40 changes: 22 additions & 18 deletions samples/Sample.BlazorWebAssembly/Client/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,42 @@ else
{
<button @onclick="Logout">Logout</button>
}
@if (this.Info != null)
@if (this.Info?.HasValue == true)
{
<h2>Id: @this.Info.id?.id</h2>
<h2>Status: @this.Info.status</h2>
<h2>Topic: @this.Info.topic</h2>
if (this.Info.latest_tally != null)
ProposalInfo info = this.Info.GetValueOrThrow();
<h2>Id: @info.Id.GetValueOrDefault()</h2>
<h2>Status: @info.Status</h2>
<h2>Topic: @info.Topic</h2>
if (info.LatestTally.HasValue)
{
Tally latestTally = info.LatestTally.GetValueOrThrow();
<h1>Votes</h1>
<ul>
<li>Yes: @this.Info.latest_tally.yes</li>
<li>No: @this.Info.latest_tally.no</li>
<li>Total: @this.Info.latest_tally.total</li>
<li>Yes: @latestTally.Yes</li>
<li>No: @latestTally.No</li>
<li>Total: @latestTally.Total</li>
</ul>
}
if (this.Info.proposal != null)
if (info.Proposal.HasValue)
{
Proposal proposal = info.Proposal.GetValueOrThrow();
<h1>Proposal</h1>
<h2>Title: @this.Info.proposal.title</h2>
<h2>Summary: @this.Info.proposal.summary</h2>
<h2>Url: @this.Info.proposal.url</h2>
if (this.Info.proposal.action != null)
<h2>Title: @proposal.Title</h2>
<h2>Summary: @proposal.Summary</h2>
<h2>Url: @proposal.Url</h2>
if (proposal.Action.HasValue)
{
switch (this.Info.proposal.action.Type)
var action = proposal.Action.GetValueOrThrow();
switch (action.Type)
{
case ActionType.Motion:
<h2>Motion: @this.Info.proposal.action.AsMotion().motion_text</h2>
<h2>Motion: @action.AsMotion().MotionText</h2>
break;
}
}
}
<pre>
@JsonSerializer.Serialize(this.Info, new JsonSerializerOptions{WriteIndented=true});
@JsonSerializer.Serialize(info, new JsonSerializerOptions{WriteIndented=true});
</pre>

}
Expand All @@ -71,14 +75,14 @@ else if(this.MadeCall && this.ProposalId != null)
@code {
public ulong? ProposalId { get; set; }
public bool MadeCall { get; set; }
public ProposalInfo? Info { get; set; }
public OptionalValue<ProposalInfo>? Info { get; set; }
public IIdentity? Identity { get; set; }

public async Task ReloadProposalInfo()
{
if (this.ProposalId != null)
{
this.Info = await this.Client.get_proposal_info(this.ProposalId.Value, identityOverride: this.Identity);
this.Info = await this.Client.GetProposalInfo(this.ProposalId.Value, identityOverride: this.Identity);
this.MadeCall = true;
}
}
Expand Down
10 changes: 2 additions & 8 deletions samples/Sample.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@
var client = new GovernanceApiClient(agent, canisterId);


var info = await client.get_proposal_info(94182, null);

var paths = new List<Path>
{
Path.FromSegments("time"),
Path.FromSegments("canister", "az5sd-cqaaa-aaaae-aaarq-cai", "module_hash"),
};
var a = await agent.ReadStateAsync(Principal.FromText("az5sd-cqaaa-aaaae-aaarq-cai"), paths);
var info = await client.GetProposalInfo(94182, null);

Console.WriteLine(info.GetValueOrDefault()?.Proposal.GetValueOrDefault()?.Title);

3 changes: 2 additions & 1 deletion samples/Sample.RestAPI/Controllers/GovernanceController.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using EdjCase.ICP.Candid.Models;
using Microsoft.AspNetCore.Mvc;
using Sample.Shared;
using Sample.Shared.Governance;
Expand All @@ -19,7 +20,7 @@ public GovernanceController(GovernanceApiClient client)
[HttpGet]
public async Task<IActionResult> GetProposalInfo(ulong id)
{
ProposalInfo? info = await this.Client.get_proposal_info(id);
OptionalValue<ProposalInfo> info = await this.Client.GetProposalInfo(id);
return this.Ok(info);
}
}
Expand Down
4 changes: 0 additions & 4 deletions samples/Sample.Shared/Dex/Aliases.cs

This file was deleted.

Loading

0 comments on commit 3ecc1c2

Please sign in to comment.