Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
feat(core): add changi network (#156)
Browse files Browse the repository at this point in the history
* feat(core): add changi network

* feat(core): add changi network

* update standard to 1.9.3

* update snapshots

* update pnpm and package jsok

* test diff node version

* revert to 1.9.0

* update standard to 1.9.3

* use fixed 18.2.21 for types/react

* update packages

* fix prettier
  • Loading branch information
pierregee authored Aug 28, 2023
1 parent 889c877 commit 0387962
Show file tree
Hide file tree
Showing 11 changed files with 651 additions and 387 deletions.
10 changes: 10 additions & 0 deletions packages/walletkit-core/src/api/__snapshots__/network.unit.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`network should resolve bip32 option for Changi 1`] = `
{
"bip32": {
"private": 70615956,
"public": 70617039,
},
"wif": 239,
}
`;

exports[`network should resolve bip32 option for LocalPlayground 1`] = `
{
"bip32": {
Expand Down
4 changes: 4 additions & 0 deletions packages/walletkit-core/src/api/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum EnvironmentNetwork {
MainNet = "MainNet",
TestNet = "TestNet",
DevNet = "DevNet",
Changi = "Changi",
}

export enum EnvironmentName {
Expand All @@ -30,6 +31,7 @@ export const environments: Record<EnvironmentName, Environment> = {
EnvironmentNetwork.TestNet,
EnvironmentNetwork.DevNet,
EnvironmentNetwork.RemotePlayground,
EnvironmentNetwork.Changi,
],
},
Preview: {
Expand All @@ -40,6 +42,7 @@ export const environments: Record<EnvironmentName, Environment> = {
EnvironmentNetwork.DevNet,
EnvironmentNetwork.TestNet,
EnvironmentNetwork.MainNet,
EnvironmentNetwork.Changi,
],
},
Development: {
Expand All @@ -51,6 +54,7 @@ export const environments: Record<EnvironmentName, Environment> = {
EnvironmentNetwork.DevNet,
EnvironmentNetwork.TestNet,
EnvironmentNetwork.MainNet,
EnvironmentNetwork.Changi,
],
},
};
Expand Down
1 change: 1 addition & 0 deletions packages/walletkit-core/src/api/environment.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ describe("environments", () => {
expect(isPlayground(EnvironmentNetwork.RemotePlayground)).toBe(true);
expect(isPlayground(EnvironmentNetwork.MainNet)).toBe(false);
expect(isPlayground(EnvironmentNetwork.TestNet)).toBe(false);
expect(isPlayground(EnvironmentNetwork.Changi)).toBe(false);
});
});
1 change: 1 addition & 0 deletions packages/walletkit-core/src/api/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function getJellyfishNetwork(network: EnvironmentNetwork): Network {
return DevNet;
case EnvironmentNetwork.LocalPlayground:
case EnvironmentNetwork.RemotePlayground:
case EnvironmentNetwork.Changi:
return RegTest;
default:
return RegTest;
Expand Down
5 changes: 5 additions & 0 deletions packages/walletkit-core/src/api/network.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ describe("network", () => {
const bip32Options = getBip32Option(EnvironmentNetwork.RemotePlayground);
expect(bip32Options).toMatchSnapshot();
});

it("should resolve bip32 option for Changi", () => {
const bip32Options = getBip32Option(EnvironmentNetwork.Changi);
expect(bip32Options).toMatchSnapshot();
});
});
6 changes: 6 additions & 0 deletions packages/walletkit-core/src/api/whale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export function newOceanOptions(
network: "devnet",
version: "v0",
};
case EnvironmentNetwork.Changi:
return {
url: url ?? "http://changi.ocean.jellyfishsdk.com",
network: "changi",
version: "v0",
};
case EnvironmentNetwork.MainNet:
default:
return {
Expand Down
26 changes: 26 additions & 0 deletions packages/walletkit-core/src/api/whale.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ describe("whale", () => {
});
});

it("should match ocean options for changi", () => {
const oceanOptions = newOceanOptions(EnvironmentNetwork.Changi);
expect(oceanOptions).toMatchObject({
url: "http://changi.ocean.jellyfishsdk.com",
network: "changi",
version: "v0",
});
});

it("should create new instance of whale api client", () => {
const oceanOptions = newOceanOptions(EnvironmentNetwork.TestNet);
const whaleApiClient = newWhaleAPIClient(oceanOptions);
Expand Down Expand Up @@ -92,6 +101,11 @@ describe("whale", () => {
const defaultURL = getDefaultDefiChainURL(EnvironmentNetwork.DevNet);
expect(defaultURL).toStrictEqual("http://devnet.ocean.jellyfishsdk.com");
});

it("should match default ocean url for changi", () => {
const defaultURL = getDefaultDefiChainURL(EnvironmentNetwork.Changi);
expect(defaultURL).toStrictEqual("http://changi.ocean.jellyfishsdk.com");
});
});

describe("whale custom provider", () => {
Expand Down Expand Up @@ -144,4 +158,16 @@ describe("whale custom provider", () => {
version: "v0",
});
});

it("should match custom provider URL for changi", () => {
const oceanOptions = newOceanOptions(
EnvironmentNetwork.Changi,
customProviderURL,
);
expect(oceanOptions).toMatchObject({
url: customProviderURL,
network: "changi",
version: "v0",
});
});
});
3 changes: 2 additions & 1 deletion packages/walletkit-ui/src/contexts/DeFiScanContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ function getNetworkParams(network: EnvironmentNetwork): string {
return `?network=${EnvironmentNetwork.TestNet}`;
case EnvironmentNetwork.DevNet:
return `?network=${EnvironmentNetwork.DevNet}`;

case EnvironmentNetwork.Changi:
return `?network=${EnvironmentNetwork.Changi}`;
case EnvironmentNetwork.LocalPlayground:
case EnvironmentNetwork.RemotePlayground:
return `?network=${EnvironmentNetwork.RemotePlayground}`;
Expand Down
10 changes: 10 additions & 0 deletions packages/walletkit-ui/src/contexts/WhaleContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ describe("Whale Context test", () => {
network: "devnet",
name: EnvironmentNetwork.DevNet,
},
{
url: "http://changi.ocean.jellyfishsdk.com",
network: "changi",
name: EnvironmentNetwork.Changi,
},
];

networkDetails.forEach((networkDetail) => {
Expand Down Expand Up @@ -132,6 +137,11 @@ describe("Whale custom provider url test", () => {
network: "devnet",
name: EnvironmentNetwork.DevNet,
},
{
url: "https://custom.changi.com",
network: "changi",
name: EnvironmentNetwork.Changi,
},
];

networkDetails.forEach((networkDetail) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,78 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Whale Context test Whale Context test for Changi should match snapshot 1`] = `
{
"asFragment": [Function],
"baseElement": <body>
<div>
<div>
<span>
{"url":"http://changi.ocean.jellyfishsdk.com","timeout":60000,"version":"v0","network":"changi"}
</span>
</div>
</div>
</body>,
"container": <div>
<div>
<span>
{"url":"http://changi.ocean.jellyfishsdk.com","timeout":60000,"version":"v0","network":"changi"}
</span>
</div>
</div>,
"debug": [Function],
"findAllByAltText": [Function],
"findAllByDisplayValue": [Function],
"findAllByLabelText": [Function],
"findAllByPlaceholderText": [Function],
"findAllByRole": [Function],
"findAllByTestId": [Function],
"findAllByText": [Function],
"findAllByTitle": [Function],
"findByAltText": [Function],
"findByDisplayValue": [Function],
"findByLabelText": [Function],
"findByPlaceholderText": [Function],
"findByRole": [Function],
"findByTestId": [Function],
"findByText": [Function],
"findByTitle": [Function],
"getAllByAltText": [Function],
"getAllByDisplayValue": [Function],
"getAllByLabelText": [Function],
"getAllByPlaceholderText": [Function],
"getAllByRole": [Function],
"getAllByTestId": [Function],
"getAllByText": [Function],
"getAllByTitle": [Function],
"getByAltText": [Function],
"getByDisplayValue": [Function],
"getByLabelText": [Function],
"getByPlaceholderText": [Function],
"getByRole": [Function],
"getByTestId": [Function],
"getByText": [Function],
"getByTitle": [Function],
"queryAllByAltText": [Function],
"queryAllByDisplayValue": [Function],
"queryAllByLabelText": [Function],
"queryAllByPlaceholderText": [Function],
"queryAllByRole": [Function],
"queryAllByTestId": [Function],
"queryAllByText": [Function],
"queryAllByTitle": [Function],
"queryByAltText": [Function],
"queryByDisplayValue": [Function],
"queryByLabelText": [Function],
"queryByPlaceholderText": [Function],
"queryByRole": [Function],
"queryByTestId": [Function],
"queryByText": [Function],
"queryByTitle": [Function],
"rerender": [Function],
"unmount": [Function],
}
`;

exports[`Whale Context test Whale Context test for DevNet should match snapshot 1`] = `
{
"asFragment": [Function],
Expand Down Expand Up @@ -365,6 +438,79 @@ exports[`Whale Context test Whale Context test for TestNet should match snapshot
}
`;

exports[`Whale custom provider url test Whale custom provider url test for Changi should match custom provider url: https://custom.changi.com 1`] = `
{
"asFragment": [Function],
"baseElement": <body>
<div>
<div>
<span>
{"url":"https://custom.changi.com","timeout":60000,"version":"v0","network":"changi"}
</span>
</div>
</div>
</body>,
"container": <div>
<div>
<span>
{"url":"https://custom.changi.com","timeout":60000,"version":"v0","network":"changi"}
</span>
</div>
</div>,
"debug": [Function],
"findAllByAltText": [Function],
"findAllByDisplayValue": [Function],
"findAllByLabelText": [Function],
"findAllByPlaceholderText": [Function],
"findAllByRole": [Function],
"findAllByTestId": [Function],
"findAllByText": [Function],
"findAllByTitle": [Function],
"findByAltText": [Function],
"findByDisplayValue": [Function],
"findByLabelText": [Function],
"findByPlaceholderText": [Function],
"findByRole": [Function],
"findByTestId": [Function],
"findByText": [Function],
"findByTitle": [Function],
"getAllByAltText": [Function],
"getAllByDisplayValue": [Function],
"getAllByLabelText": [Function],
"getAllByPlaceholderText": [Function],
"getAllByRole": [Function],
"getAllByTestId": [Function],
"getAllByText": [Function],
"getAllByTitle": [Function],
"getByAltText": [Function],
"getByDisplayValue": [Function],
"getByLabelText": [Function],
"getByPlaceholderText": [Function],
"getByRole": [Function],
"getByTestId": [Function],
"getByText": [Function],
"getByTitle": [Function],
"queryAllByAltText": [Function],
"queryAllByDisplayValue": [Function],
"queryAllByLabelText": [Function],
"queryAllByPlaceholderText": [Function],
"queryAllByRole": [Function],
"queryAllByTestId": [Function],
"queryAllByText": [Function],
"queryAllByTitle": [Function],
"queryByAltText": [Function],
"queryByDisplayValue": [Function],
"queryByLabelText": [Function],
"queryByPlaceholderText": [Function],
"queryByRole": [Function],
"queryByTestId": [Function],
"queryByText": [Function],
"queryByTitle": [Function],
"rerender": [Function],
"unmount": [Function],
}
`;

exports[`Whale custom provider url test Whale custom provider url test for DevNet should match custom provider url: https://custom.devnet.com 1`] = `
{
"asFragment": [Function],
Expand Down
Loading

0 comments on commit 0387962

Please sign in to comment.