-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refining the structure; Adding a few minor tests; Adding gateway (#8)
- Loading branch information
1 parent
a8cc6be
commit 84badfb
Showing
17 changed files
with
250 additions
and
113 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "algorealm-ui", | ||
"description": "Claim the Crown and the Sceptre of Algorand Realm", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"private": true, | ||
"author": "Cosimo Bassi <[email protected]>", | ||
"license": "GPL-3.0", | ||
|
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,9 @@ | ||
import { about } from './about'; | ||
|
||
describe(`about`, () => { | ||
it(`should return the expected string`, () => { | ||
expect(about()).toEqual( | ||
`AlgoRealm UI is an open-source terminal emulator web app built by @aorumbayev for the AlgoRealm CLI game created by @cusma. AlgoRealm UI is available under the GPLv3 license. CLI commands are identical to the original commands in the AlgoRealm documentation. However, they simplify the authentication and provide a higher degree of extensibility in the future. For more details, refer to https://github.com/cusma/algorealm - another fun way to play AlgoRealm that allows learning a few lower-level nuances of interacting with the Algorand blockchain.`, | ||
); | ||
}); | ||
}); |
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,3 @@ | ||
export const about = () => { | ||
return `AlgoRealm UI is an open-source terminal emulator web app built by @aorumbayev for the AlgoRealm CLI game created by @cusma. AlgoRealm UI is available under the GPLv3 license. CLI commands are identical to the original commands in the AlgoRealm documentation. However, they simplify the authentication and provide a higher degree of extensibility in the future. For more details, refer to https://github.com/cusma/algorealm - another fun way to play AlgoRealm that allows learning a few lower-level nuances of interacting with the Algorand blockchain.`; | ||
}; |
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,26 @@ | ||
import { changeChain } from './changeChain'; | ||
import { ChainType } from '@/models/Chain'; | ||
import store from '@/redux/store'; | ||
import { setChain } from '@/redux/slices/walletConnectSlice'; | ||
|
||
describe(`changeChain`, () => { | ||
it(`should dispatch the setChain action with the correct chain type`, () => { | ||
const spy = jest.spyOn(store, `dispatch`); | ||
const chain = ChainType.MainNet; | ||
changeChain(chain); | ||
expect(spy).toHaveBeenCalledWith(setChain(chain)); | ||
}); | ||
|
||
it(`should return the expected string`, () => { | ||
const chain = ChainType.MainNet; | ||
expect(changeChain(chain)).toEqual(`Chain changed to ${chain}`); | ||
}); | ||
|
||
it(`should throw an error if the store dispatch method throws an error`, () => { | ||
const spy = jest.spyOn(store, `dispatch`).mockImplementation(() => { | ||
throw new Error(`dispatch error`); | ||
}); | ||
const chain = ChainType.MainNet; | ||
expect(() => changeChain(chain)).toThrowError(`dispatch error`); | ||
}); | ||
}); |
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,8 @@ | ||
import { ChainType } from '@/models/Chain'; | ||
import { setChain } from '@/redux/slices/walletConnectSlice'; | ||
import store from '@/redux/store'; | ||
|
||
export const changeChain = (chain: ChainType) => { | ||
store.dispatch(setChain(chain)); | ||
return `Chain changed to ${chain}`; | ||
}; |
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,10 @@ | ||
import { IpfsGateway } from '@/models/Gateway'; | ||
import { setGateway } from '@/redux/slices/walletConnectSlice'; | ||
import store from '@/redux/store'; | ||
|
||
export const changeGateway = (gateway: string) => { | ||
store.dispatch( | ||
setGateway(IpfsGateway[gateway.toUpperCase() as keyof typeof IpfsGateway]), | ||
); | ||
return `Gateway changed to ${gateway}`; | ||
}; |
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,53 @@ | ||
import { ALGOREALM_CROWN_ID } from '@/common/constants'; | ||
import { optAssets } from '@/redux/slices/walletConnectSlice'; | ||
import { hasAsset } from '@/utils/assets/hasAsset'; | ||
import { getClaimAssetTxns } from '@/utils/transactions/getClaimAssetTxns'; | ||
import submitTransactions from '@/utils/transactions/submitTransactions'; | ||
import WalletManager from '@/wallets/walletManager'; | ||
import store from '@/redux/store'; | ||
import { IpfsGateway } from '@/models/Gateway'; | ||
import { ChainType } from '@/models/Chain'; | ||
import { Asset } from '@/models/Asset'; | ||
|
||
export const claimCrown = async ( | ||
majestyName: string, | ||
algos: number, | ||
chain: ChainType, | ||
address: string, | ||
assets: Asset[], | ||
gateway: IpfsGateway, | ||
connector: WalletManager, | ||
) => { | ||
if (!connector.connected) { | ||
return `You must connect to PeraWallet to claim the Crown of Entropy.`; | ||
} | ||
|
||
if (!hasAsset(ALGOREALM_CROWN_ID(chain), assets)) { | ||
await store.dispatch( | ||
optAssets({ | ||
assetIndexes: [ALGOREALM_CROWN_ID(chain)], | ||
gateway, | ||
connector, | ||
}), | ||
); | ||
} | ||
|
||
const claimTxns = await getClaimAssetTxns( | ||
chain, | ||
address, | ||
ALGOREALM_CROWN_ID(chain), | ||
`Crown`, | ||
majestyName, | ||
algos, | ||
); | ||
|
||
const signedTxns = await connector.signTransactions(claimTxns); | ||
|
||
if (!signedTxns) { | ||
return undefined; | ||
} | ||
|
||
const txnResponse = await submitTransactions(chain, signedTxns); | ||
|
||
return `Transactions ${txnResponse.txId} performed. 👑 Glory to ${majestyName}, the Randomic Majesty of Algorand! 🎉`; | ||
}; |
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,53 @@ | ||
import { ALGOREALM_SCEPTRE_ID } from '@/common/constants'; | ||
import { optAssets } from '@/redux/slices/walletConnectSlice'; | ||
import { hasAsset } from '@/utils/assets/hasAsset'; | ||
import { getClaimAssetTxns } from '@/utils/transactions/getClaimAssetTxns'; | ||
import submitTransactions from '@/utils/transactions/submitTransactions'; | ||
import WalletManager from '@/wallets/walletManager'; | ||
import store from '@/redux/store'; | ||
import { IpfsGateway } from '@/models/Gateway'; | ||
import { ChainType } from '@/models/Chain'; | ||
import { Asset } from '@/models/Asset'; | ||
|
||
export const claimSceptre = async ( | ||
majestyName: string, | ||
algos: number, | ||
chain: ChainType, | ||
address: string, | ||
assets: Asset[], | ||
gateway: IpfsGateway, | ||
connector: WalletManager, | ||
) => { | ||
if (!connector.connected) { | ||
return `You must connect to PeraWallet to claim the Sceptre of Proof.`; | ||
} | ||
|
||
if (!hasAsset(ALGOREALM_SCEPTRE_ID(chain), assets)) { | ||
await store.dispatch( | ||
optAssets({ | ||
assetIndexes: [ALGOREALM_SCEPTRE_ID(chain)], | ||
gateway, | ||
connector, | ||
}), | ||
); | ||
} | ||
|
||
const claimTxns = await getClaimAssetTxns( | ||
chain, | ||
address, | ||
ALGOREALM_SCEPTRE_ID(chain), | ||
`Sceptre`, | ||
majestyName, | ||
algos, | ||
); | ||
|
||
const signedTxns = await connector.signTransactions(claimTxns); | ||
|
||
if (!signedTxns) { | ||
return undefined; | ||
} | ||
|
||
const txnResponse = await submitTransactions(chain, signedTxns); | ||
|
||
return `Transactions ${txnResponse.txId} performed. 👑 Glory to ${majestyName}, the Verifiable Majesty of Algorand! 🎉`; | ||
}; |
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,18 @@ | ||
import { ChainType } from '@/models/Chain'; | ||
import { getAlgoRealmCalls } from '@/utils/transactions/getAlgoRealmCalls'; | ||
import { getAlgoRealmHistory } from '@/utils/transactions/getAlgoRealmHistory'; | ||
|
||
export const printDynasty = async (chain: ChainType) => { | ||
const attempts = 1; | ||
let algoRealmCalls = [] as Record<string, any>[]; | ||
while (attempts <= 5) { | ||
try { | ||
algoRealmCalls = await getAlgoRealmCalls(chain); | ||
break; | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
} | ||
|
||
return getAlgoRealmHistory(algoRealmCalls); | ||
}; |
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,5 @@ | ||
import { ALGOREALM_POEM } from '@/common/constants'; | ||
|
||
export const printPoem = () => { | ||
return ALGOREALM_POEM; | ||
}; |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export enum IpfsGateway { | ||
DWEB_LINK = `dweb.link`, | ||
IPFS_IO = `ipfs.io`, | ||
CLOUDFLARE_IPFS = `cloudflare-ipfs.com`, | ||
ALGONODE_IO = `ipfs.algonode.xyz`, | ||
DWEB = `dweb.link`, | ||
IPFS = `ipfs.io`, | ||
CLOUDFLARE = `cloudflare-ipfs.com`, | ||
ALGONODE = `ipfs.algonode.xyz`, | ||
} |
Oops, something went wrong.
84badfb
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.
Deploy preview for algorealm ready!
✅ Preview
https://algorealm-gf5x0xnxk-algoworldexplorer.vercel.app
Built with commit 84badfb.
This pull request is being automatically deployed with vercel-action