-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Reorganize Wallet PopUp (#945)
* Feat: Reorganize Wallet PopUp Added the function sortConnectors and applied logic to display available connectors first, followed by unavailable ones. * requested changes - Updated function import at the navbar file. - Created connectors.test.js for testing the util function. - Renamed the file to "connectors.ts"
- Loading branch information
Showing
3 changed files
with
87 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { sortConnectors } from "../../utils/connectors"; | ||
class MockConnector { | ||
constructor(id, name, isAvailable) { | ||
this.id = id; | ||
this.name = name; | ||
this.isAvailable = isAvailable; | ||
} | ||
available() { | ||
return this.isAvailable; | ||
} | ||
} | ||
|
||
describe("sortConnectors function", () => { | ||
it("should place available connectors first, followed by unavailable ones", () => { | ||
const connectors = [ | ||
new MockConnector("okxwallet", "Okx Wallet", false), | ||
new MockConnector("braavos", "Braavos", true), | ||
new MockConnector("bitkeep", "Bitget Wallet", false), | ||
new MockConnector("argentX", "Argent X", true), | ||
]; | ||
|
||
const sortedConnectors = sortConnectors(connectors); | ||
|
||
expect(sortedConnectors[0].name).toBe("Braavos"); | ||
expect(sortedConnectors[1].name).toBe("Argent X"); | ||
expect(sortedConnectors[2].name).toBe("Okx Wallet"); | ||
expect(sortedConnectors[3].name).toBe("Bitget Wallet"); | ||
}); | ||
|
||
it("should return an empty array if no connectors are provided", () => { | ||
const sortedConnectors = sortConnectors([]); | ||
expect(sortedConnectors).toEqual([]); | ||
}); | ||
|
||
it("should handle the case when all connectors are available", () => { | ||
const connectors = [ | ||
new MockConnector("braavos", "Braavos", true), | ||
new MockConnector("argentX", "Argent X", true), | ||
]; | ||
|
||
const sortedConnectors = sortConnectors(connectors); | ||
|
||
expect(sortedConnectors[0].name).toBe("Braavos"); | ||
expect(sortedConnectors[1].name).toBe("Argent X"); | ||
}); | ||
|
||
it("should handle the case when all connectors are unavailable", () => { | ||
const connectors = [ | ||
new MockConnector("okxwallet", "Okx Wallet", false), | ||
new MockConnector("bitkeep", "Bitget Wallet", false), | ||
]; | ||
|
||
const sortedConnectors = sortConnectors(connectors); | ||
|
||
expect(sortedConnectors[0].name).toBe("Okx Wallet"); | ||
expect(sortedConnectors[1].name).toBe("Bitget Wallet"); | ||
}); | ||
}); |
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,24 @@ | ||
import { Connector } from "starknetkit"; | ||
|
||
export const sortConnectors = (connectors: Connector[]): Connector[] => { | ||
const available: Connector[] = []; | ||
const notAvailable: Connector[] = []; | ||
|
||
// Sort connectors | ||
connectors.forEach((connector) => { | ||
if (connector.available()) { | ||
available.push(connector); | ||
} else { | ||
notAvailable.push(connector); | ||
} | ||
}); | ||
|
||
return [ | ||
...available, | ||
// Reorganized not available connectors | ||
...notAvailable.sort((a, b) => { | ||
const order = ["okxwallet", "bitkeep"]; // desired order | ||
return order.indexOf(a.id) - order.indexOf(b.id); | ||
}), | ||
]; | ||
}; |